Bug with arcpy in a thread

07-29-2012 10:11 PM
New Contributor
I am trying to use arcpy within a thread and am getting unexpected results from arcpy.Exists:

import threading
import arcpy

class ThreadTest(threading.Thread):
    def __init__(self,):

    def run(self):
        if arcpy.Exists(r'E:\nothing.gdb'):

if __name__=='__main__':
    tt = ThreadTest()

This results in arcpy.Exists returning True when the .gdb does not exist (or anything even close) and then an error when trying to delete it as it does not in fact exist.

If I move the import arcpy line from the top to the run method, the problem disappears, however this is not a solution as it seems to only work for the thread that arcpy is initially imported in. What if I need a second thread?

When I put the if exists test under the if __name__==... line (and therefore in the thread where arcpy is initially imported) all works fine.

For some background, I'm trying to use this with a GUI so I only need one thread, but I need the processing to happen in that thread whilst the main thread continues to serve GUI events.

Am I doing something wrong, or is this a bug?


Tags (2)
0 Kudos
1 Reply
Occasional Contributor III
arcpy does not work threaded. It is not a bug, it is a longstanding architecture issue. Please investigate using multiprocessing or some other non-threaded concurrency model for doing parallel processing.
0 Kudos