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

19490
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
JeffMoulds
Esri Contributor

Hello Shelby, I tried it at 2.1 and wasn't able to reproduce the problem. Can you give me your exact steps?

0 Kudos
ShelbyZelonisRoberson
Frequent Contributor

I didn't change a single thing. I've had a Windows task running a python script every week for the past few months. When I updated to the production version of 2.1 two weeks ago, the task no longer runs when I'm not logged in. I think there might be two issues, possibly related, and I do have a ticket into Esri Tech Support. Here's what happened and my testing steps:

  1. The task did not run as scheduled two weeks ago after updating to 2.1 (I had no issues prior to production version of  2.1, it worked in the Beta 2.1 also).
  2. I first checked to see if I could run the python script as a standalone. It failed when calling a custom model in the code. *NOTE* no changes were made to this script so the model failing was very strange since it had always worked before. Also, the model runs fine when I run it through Pro 2.1 directly, so it's not like anything changed with paths, data, etc. that would otherwise cause it to fail.
  3. To test if it was just an issue with the model, I commented out those lines of code in the python script and tried to run the script again. With these lines commented out, it runs fine as a standalone.
  4. I scheduled a Windows task for the script with the model lines commented out. Despite this, it still will not run when I am logged out. However, it does run when I am logged in. 

So, I'm back to my original problem (script not running as scheduled task when not logged in) but with an additional complication that my custom model also has stopped working in the script.

Again, I have a ticket into Esri tech support and I got an email from them this morning that they elevated my issue due to the complexity. Hopefully that means they might have an understanding of what is going on?

0 Kudos
JeffMoulds
Esri Contributor

Can you repro if you right click the task in Task Scheduler > Run? You can also send me your repro case to jmoulds@esri.com, 1.) Export the Task as an XML file, 2.) the python script (please simplify the script as much as possible, e.g. just a few lines that does something simple like export a layout to a PDF, and 3.) the BAT file used in the scheduled task, if applicable. Thanks.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Since this mentions "offline" use and Pro 2.1.1, I'm going to add this into the conversation. I'm not sure if this is 100% related, but just in case the Pro, Pro "offline" and Desktop "borrowing" is a common thread....

I'm trying to use Python 2.7 (Desktop 10.6 in my case) to import arcpy into an external Python IDE with a borrowed Desktop license(from CU license manager)  and I am having issues.  Seems to work fine if on the network so it can see my concurrent license.  I also have Pro 2.1.1 installed.

So, not sure if it is the borrowed license, being offline, Pro 2.1.1 or Desktop 10.6. that might be causing the issue.

(note, I also installed/upgrade to MS Office 365 ...enterprise license.. atlhough I don't think that is the problem).

I have a tech support call in and they are looking into it.

the other geonet thread https://community.esri.com/message/749008-re-arcpy-import-is-really-slow-2-minutes  for anyone interested.

Not hijacking this thread, just want to throw this out in case it helps solve both issues.

0 Kudos
ThomasColson
MVP Frequent Contributor

I'm having the same issues. Tasks ran fine for months...then suddenly stopped. The Python by itself runs fine, as does executing it via command prompt using service account credentials. 

ShelbyZelonisRoberson
Frequent Contributor

Thomas - have you found any resolution? I've been working with Esri the last couple weeks but they can't reproduce. I've tried everything I can possibly think of (permissions, paths, file names, etc etc). I actually got to a point where I could get the script to run when not logged in, but it would not finish (it would stop at the last step which was exporting a layout to a PNG).  Have you done any testing? If we find anything similar in our system environments it could help pinpoint the issue.

 

I ended up uninstalling the production version of 2.1 and re-installing the Beta 2.1. Everything works fine again, so something definitely changed between the two releases. I can manage with the Beta version for now, but I'd really like to be able to upgrade at some point.  

0 Kudos
ThomasColson1
Occasional Contributor

No resolution. I've tried every licensing  scenario, concurrent, named user, offline. Script works perfectly every time when I run in the Py window, will not run as a scheduled task, period. Pro/Py 3.5.x does not have a bright future (none, in fact) with us if we can't run scheduled data management tasks, of which I have about 100, all of which ran perfectly as scheduled tasks in Arc/Py 2.7.x. Why take something that works and break it? 

ShelbyZelonisRoberson
Frequent Contributor

I feel your pain. Some things that seemed to get the script to at least run partially were: 1. full UNC paths to EVERYTHING, even local paths; 2. Using concurrent licensing; 3. Adding a path to the python folder location in the "Start in" box in the Actions tab of the Windows task. 

Like I said, my script still failed at the export to PNG step, but it did partially run when not logged in (it ran at the specified time, imported arcpy, created a folder, and called an ArcGIS Pro project...but then it would stop before creating the exports of the layouts in the Pro project). 

ShelbyZelonisRoberson
Frequent Contributor

Thomas - have you happened to try this with Pro 2.2.1? I'm wondering if I should attempt to upgrade to see if it might have been "fixed". I'm still running Beta 2.1 because I don't want to break it.

0 Kudos
MichaelVolz
Esteemed Contributor

Thomas:

Have you made any progress on getting your python based Pro scripts to run when not logged in?

0 Kudos