Select to view content in your preferred language

Is there an option to disable "Run python script in process" for a Python toolbox?

6489
7
08-21-2014 09:35 AM
AaronSimmons
Deactivated User

When doing Add > Script from a custom Toolbox, one of the checkbox options on the second page is "Run Python script in process".  I have some Python code which ultimately pops up a modal window (the user chooses a cert for an HTTP connection) -- that popup window seems to fight with the "Executing Tool..." window in ArcMap.

I have proven that the same Python code added as a script to a custom toolbox with 'Run Python script in process' unchecked works fine.  (the popup window can be clicked on)

I can't seem to find any option for "Run python script in process" or not for Python toolboxes?!  Is it so integrated that it cannot be run in a separate process?  Is there possibly anything I could add to the __init__ to toggle this?  (seems doubtful)

Any insight to this would be greatly appreciated.

0 Kudos
7 Replies
JasonScheirer
Esri Alum

Use the canRunInBackground property. See these docs. I believe this is new at 10.2.

0 Kudos
AaronSimmons
Deactivated User

The canRunInBackground property did not help.  I added:

self.canRunInBackground = True

and I still could not click the popup window.

..

This got me poking around some more, and what I found peculiar is when I right-click the script and choose Properties (this is under ArcToolbox..on the .pyt file I added) --- the "Always run in foreground" is checked and greyed out where I cannot change it?!  [interestingly, right-clicking a script under a custom toolbox (under Catalog > Toolboxes)--I can uncheck the "Always run in foreground" checkbox]

Are Python Toolboxes (.pyt files)--are they forced to always run in foreground?!?

AaronSimmons
Deactivated User

Are there any Python toolbox (.pyt file) experts out there that know if .pyt files can be run not "in the Python process"?

0 Kudos
MahtabAlam1
Frequent Contributor

Have you enabled background processing in Geoprocessing Options to make it run in the background?

I tested a tool in python toolbox with a popup message. It works nicely only when self.canRunInBackground = True and background processing is enabled.

0 Kudos
RhettZufelt
MVP Notable Contributor

On the "Source" tag of the script properties, you should see the "Run Python script in process" window.  Above that, is a browse box for the "Script File".  If this is blank, the Run in process is greyed out. If you browse to a python script in the "Script File:" box, and OK, then get properties again, the box will no longer be greyed out so you can uncheck it.

It will be greyed out if you just imported the script to the tool.  You can even set a script file, uncheck it, remove the script file, then re-import the script if you need it this way (to pin to a toolbar button for example).

Hope this helps,


R_

0 Kudos
DavidChambers1
Deactivated User

Hi Aaron, I just encountered this issue myself and located this post. What I discovered was very similar to you, as soon as I set canRunInBackground to true in an existing .pyt I noticed the 'Always Run in foreground' in the .pyt's properties from the Catalog window was still checked on.  (Even after a File > Save and a catalog window refresh)

class Tool(object):
    def __init__(self):
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = True

As soon as I did File > Save As to re-create the .pyt from the IDE everything worked and the custom tool was able to be executed in the background.  Just make sure background processing is enabled in Geoprocessing > Geoprocessing options as well.  It looks like for existing python toolboxes it does not auto recognize that this option has been changed and it still runs in the foreground despite changes made to the source code.  Hope this helps!

AlexanderNohe1
Honored Contributor

I might be mistaken but an option for you is to put the logic of your tool in another script and then use os.startfile(YourPythonFile) to at least run the logic out of process.  You might want to check to see if there is a way to pass arguments to that file as well.

0 Kudos