Model Runs But Not When Exported to Python

839
13
03-13-2013 09:08 AM
MarkYoung
Occasional Contributor
Hi,
I have a model which runs fine - tested OK. I wish to run this model once a week out of hours as a scheduled task on the server so I exported the model as a python script and added this script in as a scheduled task. For some reason it does not run giving me an error saying the table already exists. That is correct the table does exist and I wish to overwrite which the model does OK but the scheduled task fails.
Any ideas would be appreciated.
Thanks
Mark
0 Kudos
13 Replies
MelanieSummers
Occasional Contributor III
Hi Mark,

I suggest you take a look at this blog about exporting models to python.

You probably need to add the following to your script:

arcpy.env.overwriteOutput = True

Best,
Melanie S.
0 Kudos
MichaelVolz
Esteemed Contributor
Mark:

Are you running the python script on a Windows Server (2003 or 2008, etc.)?

If so, are you running it with highest privileges set?

If so, do you have it set to run whether user is logged on or not?

What version of ArcGIS Desktop do you have installed on the machine that you are running this scheduled task?

Under Action do you have Program/script set to the path of the python.exe file and under Add arguments do you have the path to the specific py file?
0 Kudos
MarkYoung
Occasional Contributor
Hi,
Thank you both for your responses.
The server is windows 2008 R2

I added the code:
# Set overwrite to true
arcpy.env.overwriteOutput = True
to the top of the python file (presume you add at the top of the file)

I also set the task to run with the highest privileges as suggested.
It runs whether the user logs in or not
ArcGIS desktop 10.0 is installed on the server
Within the scheduled task I have the action pointing to the .py file rather than a .exe
There is nothing in the arguments box pointing to a .py file

Thanks
Mark
0 Kudos
MichaelVolz
Esteemed Contributor
Mark:

Do you have any logging to determine at what point the script fails or if it even initiates?

You might also try creating a bat file to call from the scheduled task and then call the python script from the bat file.  This is especially useful if you want to run a series of python scripts one after the other.
0 Kudos
MelanieSummers
Occasional Contributor III
Mark,

If you run the model using the following syntax, do you get the same error?

import arcpy
arcpy.ImportToolbox(�??c:/mytools/geometrytools.tbx�?�, �??mytools�?�)
arcpy.CreateRegularPolygons_mytools(parameter1, parameter2)

Best,
Melanie S.
0 Kudos
BrettWehs
New Contributor II
We're running into a very similar situation.

We started out exporting the model as a python script, which would fail. So we switched to using python to call the model and this particular model doesn't run to completion with that method. We have managed to call a smaller/shorter model successfully using python.

The model that we want to run takes approximately 20 minutes to run when we run it by hand from ArcCatalog, but it doesn't run to completion when scheduled in Task Scheduler using python to call it.

We're using 10.1, 2008 R2
0 Kudos
MichaelVolz
Esteemed Contributor
Brett:

Do you know if your python script is even being initiated when run as a scheduled task?

Are you using any SDE connections?

Are you running the model itself on the 10.1 2008 R2 machine?  Or did you run the model on another machine and just try to run it as a scheduled task on the 10.1 2008 R2 machine?
0 Kudos
BrettWehs
New Contributor II
Brett:

Do you know if your python script is even being initiated when run as a scheduled task?

--According to the Task Scheduler Summary the runs are succeeding, however they finish in about 5 minutes (the model run by hand is approx 20 minutes to completion)

Are you using any SDE connections?

-- Yes, the initial connections are SDE, it then exports the data to a staging File GDB and finally to a Personal GDB for export to be incorporated to the outside program

Are you running the model itself on the 10.1 2008 R2 machine?  Or did you run the model on another machine and just try to run it as a scheduled task on the 10.1 2008 R2 machine?

--Thanks for this insight, this is where my problem is (I think) The model runs fine on another machine, and when I schedule it the history tells me that it's run successfully, however it's not running to completion.


Sorry for the delay in replying to this, I was trying a few different things to fix it.
0 Kudos
MarkYoung
Occasional Contributor
Hi,
I had thought the fault is with the composition of the model rather than the script failing as I started to get locks from running the model direct as well as the scheduled task. Instead of overwriting the feature class I adjusted the model (after versioning the feature class in the Sde) to delete features/attributes then append the updated features/attributes then apply priviliges.

From looking at an other post on this thread you can determine if your model is failing or if your scheduled task is failing by opening the scheduled task properties, click the actions tab, highlight your task, click edit to show the path to your script eg: "\Python Scripts\YOURSCRIPT.py" then opening a command window, right click, paste then enter. This will run your python script - or any other .bat file etc directly.

Unfortunately I am still getting a (0x1) error.

There was some advice from melanie about code;
import arcpy
arcpy.ImportToolbox(�??c:/mytools/geometrytools.tbx�?�, �??mytools�?�)
arcpy.CreateRegularPolygons_mytools(parameter1, parameter2)


but I am unsure where to add this code.

Thanks
Mark
0 Kudos