Select to view content in your preferred language

Last run result message 0xF6 when trying to run a python script using Windows Task Scheduler.

10108
31
Jump to solution
09-10-2020 05:54 AM
MichaelTorbett
Frequent Contributor

I am running several python scripts on a schedule on a virtual machine that has ArcGIS Pro 2.6.1 installed. I am using the python.exe from my Pro python environment to run all of the scripts in task scheduler. However ever since ArcGIS Pro version 2.5.2, I have been getting the message 0xF6 in the last run results. The crazy thing is that this happens sporadically. Sometimes the tasks run fine and other times they don't. All of my python scripts run fine by themselves. 

Has anyone else had this issue and know of a fix? 

Thanks,

Michael 

31 Replies
JeffHaupt
Emerging Contributor

I notice this topic keeps getting updated with different users having the same issue and trying different approaches to the problem with mixed results.  Has anyone from ESRI ever acknowledged this issue and recommended a certain approach that entities should take to handle the issue of Scheduled Tasks that rely on Arcpy to run? 

0 Kudos
SStopyak_BruceHarris
Regular Contributor

I have the same problem. I had mine set to run a bat file that calls propy.bat and the script. I'm going to try the solution of running pythonw instead. I have also noticed that either arcpy or the api fails to import intermittently when running scripts in PyCharm. I think it may be related. One last observation is that scripts seem like they fail when the user gets signed out of Pro. Soon, ArcDesktop's 2.7 will no longer be viable for scripted processes. I'm extremely uneasy about this because using Pro for automation has so many issues right now. I've had automated tasks running in 2.7 without failing for months on end. With Pro, I'm lucky to go a week or two without a failure. 

0 Kudos
FlorianSteiner
Occasional Contributor

I just had a ticket with ESRI regarding this issue. I have the problem even if using pythonw.exe or the scheduling using ArcGIS Pro. Their response was: No support, since a Windows tool ist concerned. My objection, that ArcGIS Pro uses this tool didn't change their optinion. I have to add, that this was a ticket not directly with ESRI Inc. but with "ESRI Deutschland". They were stilll trying to be helpful, which is why I've sent them a small test-script which they were able to run with no problems in ArcGIS Pro and Windows Task Scheduler. There was sadly nothing more they could do.

0 Kudos
JeffHaupt
Emerging Contributor

Thanks for that update.  I was thinking about opening a ticket, but I'm not sure I will if this is the response that I can likely expect. The interesting thing is that I've noticed this "crash" a few times when I am testing scripts by simply running the script in the command line (no task scheduler), nothing happens for a few seconds and then a new command line appears without the python script running. I have yet to experience this issue running a python script with any standard python library.  

0 Kudos
GregHorne
Regular Contributor

We have run into Task Scheduler issues where sometimes the "import arcpy" statement is crashing  Python.exe.  This  is with Python3.  It is not an issue with Python2.  I have confirmed the issue on 2 Windows Server 2019 and 4 different Windows 10 computers.

The scripts run just fine from VS Code and the command line.  In fact these are not particularly new scripts.

I have one script that runs every 5 minutes.  In an hour it might crash 3~4 times on the import arcpy statement.

 

0 Kudos
FlorianSteiner
Occasional Contributor

We just recently found out that it seems to be related to security features in our business environment. Our IT department uses "Cisco AMP" als malware protection. Temporarily deactivating this application solved the issue so far.

Before that, we used a workaround using batch files to check the error code and running the script again if it failed. Source: https://community.esri.com/t5/arcgis-api-for-python-questions/error-code-246-when-attempting-to-impo... 

Hope this helps!

0 Kudos
CarmenDurham
Frequent Contributor

Florian,

I sent you a private message but perhaps you never received it.  I would like to find out if your organization determine what it was with CiscoAmp that was causing the problem?   Were you ever able to fix the problem or did you have to add the extra DOS code to every batch file that "retries to run the batch file after a pause?"

0 Kudos
JamesHood
Regular Contributor

Sorry for the long story here but this is everything I did to trouble shoot and resolve this issue over the course of a long time and I wanted to share in case anybody else is stuck as I was.  



Whenever I schedule scripts to run using Windows task Scheduler, sometimes they run and sometimes they do not.  It seems intermittent and random for when they would choose to fail.  0xF6 is the “Last Run Result” we would receive in windows task scheduler.

Note that this problem only started after I converted my scripts from python 2.7 to 3.x and started using the pro interpreter.  2.7 never had any problems but I need to switch to 3.x

 

Note also that the scripts always run no matter what when I manually run them.  This is only a scheduled task problem

 

We are using VM server with windows datacenter 2022 but we were experiencing the same problems on an older VM running an older OS, maybe Windows Server 2016.

 

We tried switching from python.exe to pythonw.exe did not resolve the issue.

 

We tried setting up a batch file (.bat) to execute the scripts and then have task scheduler execute the batch file  and this had the same result.

 

I tried making lots of changes in task scheduler like Run with Highest Privileges, run whether user is logged on or not, run only when user is logged in, making sure user is logged in, etc., no combination of these had any effect.

 

Speaking with Esri support they recommended the following: 
1. Import script into .tbx as script tool then schedule to run from within Pro, this will add it to task scheduler anyway but it creates its own task with error logging.

2. Use a .tbx rather than .atbx (since .atbx is new and might have kinks to iron out.

3. Open the task in task scheduler to find the path to the new task.py and open that to see the path to where the logs are created.  Should be something like this:  "C:\Users\me\AppData\Local\ESRI\ArcGISPro\Geoprocessing\ScheduledTools\NameOfYourProject\task.py"

4.  Then you can open the logs to see meaningful errors not just the meaningless 0xf6 in Task Scheduler.  With meaningful errors you can work to resolve the issue.  

 

So I did that and it still failed with 0xF6 and I found that in fact the logs were not being created at all which suggested that the pythonw.exe was not even being allowed to start executing since not even an empty log was created.

So we asked IT to check the anti-virus and other security systems on the server that might be preventing it from executing.   They found no issues.

Finally, IT checked some local security policies.  T
here’s a local security policy on each server that they set to prevent bad guys from mining bitcoins I guess.   They adjusted these to add the “logon as a batch job” permission for my user on that server.  Finally the 0xf6 errors stopped and everything runs as it should for the past week.

So hopefully I’m not speaking too soon but this looks resolved for me.  I hope this helps somebody else.

0 Kudos
CarmenDurham
Frequent Contributor

James,

Thank you for posting this.  I see you added this since I first looked at this post.  We have been battling this same exact thing since converting MANY python scripts to 3.  The intermittent-ness is driving us nuts.  I have submitted to Esri and they are basically saying it is out of their wheelhouse. I ran tests with very basic scripts with nothing but import commands.  The one without "arcpy" ran constantly without fail.  The one with "import arcpy" ran 2/3 of the time.  

I have yet to call IT and have them check the policy, but I want to thank you for updating this post.  You have given me one more thing to try......  This has been driving me bonkers.  We went from never having to monitor these tasks when using 2.7 to having to access the servers EVERYDAY in task scheduler to determine what didn't run.  When you have 20-30 scripts running nightly on a few servers, that is a lot more overhead for supposedly converting to something "better".

I'll repost if this is the solution for us.  I'm just happy to have something else to try!

 

0 Kudos
JamesHood
Regular Contributor

Thanks Carmen, 

I'll add that since that change was made and since my post above, our server has run all of its tasks successfully, without fail, for 30 days so.  I am satisfied that we resolved the cause of our issue. 

0 Kudos