I would like to run a multiprocessing task from a python add-in tool. My issue is that the process keeps failing. Basically crashes ArcMap.

Here is my basic code:

def function(startOID, endOID, fc):

    wrksp = r"c:\temp\mp_addintest\data\test_%s.txt" % (int(startOID) + int(endOID))
    # real logic removed to dumb it down
    with open(wrksp, 'w') as writer:
        writer.write("%s to %s from %s \n" % (startOID, endOID, fc))
    return wrksp
class btnMP(object):
    """Implementation for src_addin.MPButton (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pool = None
            pythonExe = os.path.join(sys.exec_prefix, 'python.exe')
            pool = multiprocessing.Pool(4)
            results = []
            for i in xrange(4):
                results.append(pool.apply_async(function, [str(1),
            for result in results:
                print result.get()
            del pool
            print 'error'

If I run the code outside of ArcMap or from a toolbox, it works without a problem, but when I put the logic inside a button, it causes arcmap to crash.

My guess is that ArcMap is running in process for all python add-ins. Is there a work around for this issue?

I've tried adding in the freeze_support() to the code as well, but that did nothing as well.

  • 1
    If ArcMap is crashing, contact your ESRI support. if they can replicate it they'll acknowledge its a bug (and maybe even fix it one day). – GIS-Jonathan Oct 31 '12 at 10:40
  • Have you installed all 5 Service Packs for ArcGIS 10.x that are already out? Maybe that'll help – Sergios Kolios Nov 2 '12 at 16:07
  • The OP is using 10.1 – Petr Krebs Nov 2 '12 at 16:14
  • Also service packs are cumulative so you only need to install the latest one, not each in succession. – blah238 Nov 2 '12 at 20:23
  • SP1 for 10.1 was released this week. – Timothy Michael Nov 2 '12 at 21:58

Parallel processing is easier 'shown than done.' In the case of stuffing this all into a button, I'm guessing two issues:

  1. Multiple threads block the ArcMap UI thread, or
  2. ArcMap puts its own schema lock on the data source and doesn't permit the python process access to the data.

Hmm looking further issue has been documented here in an ArcGIS Resources page. Schema lock looks like the culprit.

| improve this answer | |
  • Not sure if you meant to link something other than what you did (an ArcGIS forums post, not an official document). – blah238 Nov 1 '12 at 6:57
  • The forum is the correct link. When someone finds more official documentation they can feel free to post it. – WolfOdrade Nov 1 '12 at 18:07
  • Thank you for your suggestions. I believe it's actually caused by #1. The thread blocks for ArcMap UI. I am use an SDE database, so schema locks are not my issues here. – code base 5000 Nov 5 '12 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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