Python 3.x Scheduled Task Fails

4113
11
06-29-2017 09:33 AM
mpboyle
Regular Contributor

I am in the process of migrating a scheduled task from ArcMap to ArcGIS Pro that exports maps to PDFs on a daily basis.  I have the python script written, and it executes as expected when running through an IDE (PyCharm) using the python executable delivered with ArcGIS Pro (..\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe).

When I try executing the same script through Windows Task Scheduler, I can tell the script is running because a .txt file is generated to log processes, however, at some point the script is failing as the maps are not being exported.  The task scheduler returns a code of 0xFFFFFFFF and I haven't found anything of substance for this code.  There are no warnings or errors in the task history either to give any clues.

We have several other tasks that are running just fine using python 2.7 along with ArcMap/ArcGIS Desktop using my domain account, so the username I'm using has sufficient permissions to execute a task.

I also have ArcGIS Pro setup to login automatically, which again, works fine through the IDE.  I tried using a Single Use license, with the same result.

If I comment out all the ArcGIS Pro / arcpy functions, the script will execute as expected through Task Scheduler (creates a log, and sends an email).  It seems to be specific to the arcpy functions.

Is anyone running a Windows Task Scheduler task using ArcGIS Pro projects successfully?  If so, am I missing something?  Is there some sort of permission setting I'm missing?  Any ideas of where to look...?

11 Replies
MichaelVolz
Esteemed Contributor

I don't believe this will work in versions previous to Pro 2.0.

Take a look at this thread:

https://community.esri.com/thread/197214-python-351-script-wont-run-via-windows-task-scheduler-when-... 

0 Kudos
mpboyle
Regular Contributor

I am using ArcGIS Pro 2.0 (Single Use Advanced)...and after reading through the thread, my script will work ONLY when the task is set to 'Run only when user is logged on'.  If I try to execute the script using 'Run whether user is logged on or not' it will fail.

Thanks for pointing me in the direction of the other thread.

MichaelVolz
Esteemed Contributor

Do you have the ability to spin up a Windows Server 2016 server to see if the scheduled task would work there if not logged onto the server?

Zach_Robinson
New Contributor III

I can also only run py3 scripts in Windows Task Scheduler when the task is set to Run only when user is logged on. It sounds like from this thread and others that upgrading to Windows Server 2016 is the only sure way to resolve the issue. Hopefully ESRI releases guidance soon.

0 Kudos
MichaelVolz
Esteemed Contributor

What kind of machine are you using when running this script (workstation, server, other)?

0 Kudos
Zach_Robinson
New Contributor III

Running Windows Server 2012 R2

0 Kudos
MichaelVolz
Esteemed Contributor

Is this a machine you are currently running ArcMap's python 2.7 based scripts from in Windows Task Scheduler?

Does your organization support Windows Server 2016 at this time?

0 Kudos
Zach_Robinson
New Contributor III

Yes, I run a handful of py2.7 scripts in task scheduler from the server machine. They run fine with the option Run whether user is logged on or not set to True. I also have left Run with highest privileges unchecked when running 2.7 scripts and they run without issue. 

And no, our city does not yet support Windows Server 2016. 

0 Kudos
DarylHochhalter
Occasional Contributor

I have the same issue running Python 3 task on Windows server 2019. I have actually attempted to use only when user is logged on, but that really isn't an option anyway. Running the same scripts as a task using Python 2.7 works fine. I can run the scripts in python 3 manually on the same machine, but not as a task. Wondering if it could have to do with the Conda environment and the fact that the system PATH info might be pointing to arcpy for the 2.7 environment?

0 Kudos