Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. Any thought or suggestion would be appreciated.

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):
        tTotal += 1
        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,))

    for t in thread_list: 

    print "total = %d"%tTotal    

tTotal = 0
conn_string = r"C:\test_conn.sde"
threadLock = threading.Lock()
mt(conn_string, 5)

share|improve this question
How do you know it fails, what happens? Does it work if you take out all the multithreading stuff? – blah238 Apr 2 '14 at 21:47
up vote 8 down vote accepted

This just plain won't work, you're going to need to look into multiprocessing if you want parallelism. ArcGIS Desktop/Server's architecture is based on the COM Single-Threaded Apartment model, meaning that any objects created on one thread can only be used on that thread. You can create a new ArcObjects object graph on another thread (see the linked documentation), at which point you'd need to use comtypes on the other thread(s) and use ArcObjects via the API generated by comtypes. This isn't for the faint of heart.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.