Refresh Python script with ArcGIS Pro tool?

1689
3
07-23-2020 01:01 PM
DavidHeacock
New Contributor II

I'm debugging some arcpy scripts that are failing when running in Pro (that's for another time). As a part of that process, I'm finding that when I make edits to my scripts in another IDE, the updated code is not being run when I re-run the tool in Pro. Because of this, I'm forced to reboot Pro every time I make a script edit which is really slow. Is there any other way to refresh the script within the tool?

To clarify, the process is:

- I run a tool within Pro that references a .py file

- I make changes to code within an IDE to the .py file referenced by the tool (and save, of course)

- in my Pro History tab, I re-run the tool (so I don't have to manually update all my parameters)

- the tool runs again, however it uses the code from before I made any edits in my IDE. i.e. it's not reflecting my edits

3 Replies
DanPatterson
MVP Esteemed Contributor

"I re-run the tool (so I don't have to manually update all my parameters)"

That is problem, the tool doesn't get refreshed, it is better to start a new instance of the tool.  And when testing, you can set defaults for the parameters.

This is particularly important if there are imports in your script.  You can trigger a reload by adding 'reload' to your code

from importlib import reload

import arcpy
import something_else

reload(arcpy)
reload(something_else)

It is usually enough to restart the process


... sort of retired...
DavidHeacock
New Contributor II

I see how that's working, thanks for the reply and the snippet. I'm still running into the issue sometimes, even when creating a new instance of the tool. I'll try adding in some of the reload() functions.

0 Kudos
ConradSchaefer__DOIT_
New Contributor III

@DavidHeacock 

Encountered the same issue. Had a main script that imported custom py modules containing code for classes. Was unable to get the tool to import the latest supporting module code properly, it is as if the module is cached somewhere and so changes made were/are never brought over. I could not trigger a refresh successfully until despite pointing to other scripts and coming back, copying the tool, and right clicking on the toolbox and using "Refresh". Nothing worked until restarted Pro. I put @DanPatterson reload() into the script and now it appears to be importing the module each and every time. Knock on wood!

The reload call was the solution for me, fingers crossed it holds. Thanks

@SusanHmel__DOIT_ 

0 Kudos