I am learning multithreading and thinking about using it with Arcpy. The example I am working on doesn't have much practical reasons. However, I don't know why it fails on the line "arcpy.Exists(fcPath):" even though the SDE is running and the feature class in question is accessible in ArcCatalog. It didn't help if I used env.workspace.
import threading
import arcpy
from arcpy import env
def tf(conn_string):
global tTotal
#env.workspace = conn_string
fcName = r"GIS_USER.TEST_FC"
fcPath = conn_string + "\\" + fcName
if arcpy.Exists(fcPath):
threadLock.acquire()
tTotal += 1
threadLock.release()
else:
print('%d: failed to connect to %s'%(tTotal, conn_string))
def mt(conn_string, step):
global tTotal
thread_list = []
for num in range(step):
t = threading.Thread(target=tf, args=(conn_string,))
thread_list.append(t)
t.start()
for t in thread_list:
t.join()
print "total = %d"%tTotal
tTotal = 0
conn_string = r"C:\test_conn.sde"
threadLock = threading.Lock()
mt(conn_string, 5)