Select to view content in your preferred language

Python Schedule task not running because of arcpy.

4573
13
05-13-2013 07:59 AM
TiagoRibeiro
Deactivated User
Hi everyone,

I have this really simple Python script, that basically copies a file:
import os, shutil, time
originalSDDraft = "C:\\Esri\\test.sddraft"
localtime = time.localtime(time.time())
filesPath = os.path.dirname(originalSDDraft)
sddraftFile = filesPath + '\\' + str(localtime.tm_min) + str(localtime.tm_sec) + os.path.basename(originalSDDraft).replace('.sddraft','_copy.sddraft')
if os.path.isfile(sddraftFile):
   os.remove(sddraftFile)
shutil.copy(originalSDDraft,sddraftFile)

When I run it on a Windows Server 2008 R2 64Bit both through command line and as a scheduled task, it does what it's suppose to do.
When I import the arcpy module, then the "fun" begins. I'm only able to run it as a schedule task if:

  • "Run only when user is logged on" is selected.

  • The user has administrator privileges.

Does any one knows why by just importing the arcpy module the script stops to work as a scheduled task with the option "Run whether user is logged on or not" selected?
Any help would be appreciated!
Thanks,

Tiago
Tags (2)
0 Kudos
13 Replies
MichaelVolz
Esteemed Contributor
I think it might have to do with the version of python you are using.  I think it might be trying to use the 64 bit python version which can only if you have it enabled for background processing.

Are you by any chance using ArcGIS for Desktop v10.1 on this server?

Disregard above as I do not think this is the issue.

I have all my scheduled tasks set to:

�?�"Run only when user is logged on" is selected.
�?�The user has administrator privileges.

on a Windows Server 2008 server machine.  This is the only way I was able to get the scheduled tasks to run properly.  I would just check have "Run only when user is logged on" and check "Run with highest privileges".  This is how my server's Scheduled Tasks have been configured and successfully running for 6 months.
0 Kudos
TimDine
Frequent Contributor
I have a number of scheduled process which run on 2008 Server 64 bit.  They do not use the 'run only when the user is logged on' or the 'run with highest privleges' settings.  I do make sure to put the full path to both my script and the python.exe that I want the application to run as which for me is at "C:\python27\arcgis10.1\python.exe pathToMyScript\script.py"
0 Kudos
LucasDanzinger
Esri Frequent Contributor
What type of Windows user profiles are you using? Are you perhaps in a Power User group, or are you an Administrator? We did have a bug logged for people in a Power User group, and it is not reproducible in 10.2 (just 10.1).

NIM089224 - Arcpy does not import when logged out and running as a scheduled task and the user is in the Power User Group.

Interestingly, in this case, importing arcgisscripting did work.
0 Kudos
curtvprice
MVP Esteemed Contributor
We have had problems with this too -- for regular users -- here's the NIM we have logged:

[#NIM066910  A script run from Task Scheduler with the setting "run whether user is logged on or not" fails to initialize ArcPy when the license is single-use. ] 
No workaround identified for version 10.1.


At 10.0, a workaround was to have a concurrent license available for arcpy to load.

Glad to hear this may be finally fixed at 10.2; it's a real show-stopper of a bug.

I will definitely test it first time I get a chance.
0 Kudos
TiagoRibeiro
Deactivated User
Thank you for all your feedback.

Michael:
The user that is going to run this task can't have admin privileges, and since it runs fine when "Run only when user is logged on", I think the problem isn't permissions.

Tim:
I've tried that way and only referencing the script, the results are the same.

Lucas:
The user setting up the task is part of the Administrators group, and the user running the task is a LOCAL user not part of any particular group, besides the "Users".

Curtis:
That issue seems very similar to what I'm experiencing. In the server I have both AG Server and AG Desktop 10.1 installed with single use license. What changes you had to make, besides the license, to run the tasks?

Just to give a summary of the situation.
Enviroment:

  • Server is a VM, with Windows Server 2008 R2 SP1, with 2GB of RAM

  • It has installed both AG Server and Desktop 10.1, with SP1


Task Config that works:
[ATTACH=CONFIG]24283[/ATTACH]

Task configs that don't work:
[ATTACH=CONFIG]24284[/ATTACH]
[ATTACH=CONFIG]24282[/ATTACH]

I've also included a zipped file with the python scripts, and the .bat file.

Any more ideas are appreciated, and you if need any more details let me know.

Tiago
0 Kudos
curtvprice
MVP Esteemed Contributor
That issue
[indent][#NIM066910 A script run from Task Scheduler with the setting "run whether user is logged on or not" fails to initialize ArcPy when the license is single-use.]  [/indent]
seems very similar to what I'm experiencing. In the server I have both AG Server and AG Desktop 10.1 installed with single use license. What changes you had to make, besides the license, to run the tasks?


(I have exchanged a private message with tribeiro about this.)

Just to update everyone, we've determined that:

  • This issue exists in ArcGIS 10.0 and 10.1.

  • At 10.0 only, if you modify the Desktop license configuration from Single-Use to Concurrent licensing, the scheduled task will run even the user is not logged in.

  • (This change equires running ArcGIS Administrator with elevated privileges. I have a VBScript script that can do this by modifying registry keys, but it also requires elevated privileges to run.)
  • The 10.0 workaround does not work at 10.1. Our USGS user that was having this problem is doing a less optimal workaround: leaving her workstation logged on at night (screen locked of course!) so her scheduled task can successfully launch arcpy.

  • Esri thinks this is reportedly fixed at 10.2 and I am trying to get around to testing it.

0 Kudos
TimDine
Frequent Contributor
I'm now moving my scripts to 10.1 SP1 on our production servers as part of an upgrade.  All of my scripts used to work fine.  Now when they're supposed to launch over night they fail with code 0xC0000005 (Seems to be an access violation).  These must work at 10.1 and can't rely on an upgrade to 10.2.  A script without arcpy in it works fine.  A script with the code below fails with the fault listed above.

import arcpy
print "Hello World"


Have you made any progress on this issue.
0 Kudos
curtvprice
MVP Esteemed Contributor
Have you made any progress on this issue.


I viewed the NIM and it now states the workaround to use arcgisscripting. Esri tech support may be able to help you modify your script to do what you need to do using arcgisscripting instead of arcpy.

I recommend contacting tech support, and be sure and reference NIM089224.

[ATTACH=CONFIG]25475[/ATTACH]
0 Kudos
TimDine
Frequent Contributor
Modifying to use arcgisscripting I'll lose all of the performance benefits I've gained with faster cursors and some new tools.  That's an unfortunate answer from them.

I'm trying the 'Run with highest privledges' option selected which seems to have a positive impact (combined with run if user is logged in or not).  It's allowed me to run my scripts, but it may only be possible because my service running account is in the local admin group.

I'd be curious what requires the extra privledges.  The scripts I'm using should only need to read files, possibly aside from compiling the py files into pyc files.
0 Kudos