Python 3.5.1 script won't run via Windows Task Scheduler when user logged off

19563
79
Jump to solution
06-23-2017 09:14 AM
ShelbyZelonisRoberson
Frequent Contributor

I have a python 3.5.1 script that uses ArcGIS Pro 1.4.1 to export some layouts to PNGs. The script runs with no problem from Windows Task Scheduler when I check the option "Run only when user is logged on", however, I really need to run the script when I am logged off.  

I'm confused because I have other Python scripts (version 2.7) that run on the same server/user account via Task Scheduler while I am logged off with no problem. I've set them up with the exact same properties as my python 3.5.1 script... the only difference is the path to the python and the fact that the other scripts use ArcMap and not ArcGIS Pro. 

Has anyone else had this issue and found a way to solve it? I've set up everything using a service account on a server with admin privileges. I have the properties in Task Scheduler set to run with the highest privileges as well. 

79 Replies
curtvprice
MVP Esteemed Contributor

We had an issue with Desktop (ie arcpy python 2.7) where the user had to be logged in. Arcpy would fail to initialize. The fix was to set up the user with a concurrent license and then all worked with the user logged off setting. Esri support didn't help us much either on this.

Does your organization have a concurrent license server? That maybe the way to get this working.

0 Kudos
ShelbyZelonisRoberson
Frequent Contributor

Interesting. I'm using concurrent licensing for ArcMap, and all my python scripts work for that setup. My Pro license is Named User. I guess I could try switching my Pro license to concurrent?

0 Kudos
ShelbyZelonisRoberson
Frequent Contributor

I switched my Pro license to concurrent and tried scheduling the script again; it still will not worked with the option checked "run whether user is logged on or not".

0 Kudos
curtvprice
MVP Esteemed Contributor

Unfortunate. Since Esri apparently doesn't wish to the support this....  Here's the bug number from Desktop:

NIM066910 - A script run from the Task Scheduler with the setting, ‘run whether user is logged on or not’ fails to initialize ArcPy when a single-use license is used.

0 Kudos
ShelbyZelonisRoberson
Frequent Contributor

Thanks. I wrote back to Tech Support basically begging them for any ideas/help since I'm pretty convinced this has to do with ArcGIS Pro. I'll post the resolution if I ever find one. 

curtvprice
MVP Esteemed Contributor

There is something about a Windows task scheduler shell that is different. For sure your mapped drives don't show up in that environment, but I think the problems importing arcpy may have to do with licensing issues. Until we tried concurrent import arcpy would fail with a NotInitialized error. 

0 Kudos
KevinHibma
Esri Regular Contributor

Hi Shelby,

I just tried your workflow and it worked fine for me. Here are the particulars of my test:

License as Concurrent use (connecting to a license manager)

Python script:

import arcpy

p = arcpy.mp.ArcGISProject("C:\\arcgisserver\\documents\\GPService\\ProGPPDS.aprx")
layout = p.listLayouts()[0]
layout.exportToPNG("c:/temp/KEVIN.PNG")

Task scheduler settings:

  • Run whether user is logged on or not
  • Do not store password is UNCHECKED (I entered my password when I made the task)
  • Configured for Windows 2016 (and 2008, I created two tasks)
  • Occurs at: just a time I set for today, then logged off before it ran
  • Starts program:    C:\ArcGIS\bin\Python\envs\arcgispro-py3\python.exe
  • Argument:   C:\PythonStuff\ExportPNG.py
  • No other settings configured

Like I said, I logged out. Let the task run. Came back and have c:\temp\kevin.png waiting for me.

Checking the history of the task I see that it ran successfully.

Task Scheduler successfully finished "{d7f8189f-2cd6-4fb2-b465-95e91a6464c7}" instance of the "\KEVIN - python export PNG" task for user "domain\kevin".

Note - this is using Pro 2.0 (which will be available to you soon). I really dont think there is any difference between 1.4 and 2.0 in regards to this workflow.

If this continues to not work for you, can you provide more information. Such as your script, messages from the task scheduler, task scheduler settings, etc.

MichaelVolz
Esteemed Contributor

Windows Server 2012 had other GIS (ArcGIS Server services) issues associated with it as reported on geonet today, so maybe that is where the problem lies.

0 Kudos
ShelbyZelonisRoberson
Frequent Contributor

Thanks Kevin. My testing workflow is exactly the same as yours except I configured for 2012 and 2008 instead of 2016. Maybe I do need Pro 2.0... I am in the Beta testing group but for a named user license, my license manager for concurrent licensing only gave me the option to go up to 1.4. 

0 Kudos
KevinHibma
Esri Regular Contributor

Focus your efforts with concurrent or single use license. If you're using named user.... it should work, the big unknown is if the "app" is still logged in. There is a period of time that the license should remain valid. However, since you're not logged in and have an active windows session, you cant guarantee that you're logged in. If you license singe use or concurrent, when you "import arcpy" from the script all the bits and pieces just get the license from the computer or network and all should work just fine (like you see it working from ArcMap).

And yes, its possible its an OS level setting. I dont have a Win2012 machine to put Pro on (I just went to 2016). I'll see if I can find a colleague to help test on that.  I assume you're using your domain account to run the task? Or a local account on  the machine?

Its also possible its a 1.4 issue fixed in 2.0 -- although I did a quick sweep of bugs and didn't see anything. (If it was a fixed bug, its very possible I missed it in the quick search I did.)