Refresh Python script with ArcGIS Pro tool?

471
2
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

0 Kudos
2 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