Select to view content in your preferred language

Script using Python API and Windows task scheduler

3704
9
Jump to solution
06-08-2021 07:50 AM
AliciaShyu
Frequent Contributor

I have a script that uses the Python API to logging into the server, stop geocode services, rebuild locators and start services.

Is there a way to use Windows task scheduler to run this script. I've tried this Schedule a Python Script using Windows Task Scheduler and Run stand-alone scripts without success.

Edited: I'm using Windows task scheduler on our server machine where other python scripts work correctly in the task scheduler. 

0 Kudos
1 Solution

Accepted Solutions
AliciaShyu
Frequent Contributor

I was able to add the script to task scheduler using the python.exe file in arcgispro-py-clone folder.

I have a clone folder because I had to install some python packages that are not part of Pro. Pro creates a clone folder when you install additional packages. The location of that folder is C:\Users\(user name)\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone

ProCloneFolder.png

View solution in original post

0 Kudos
9 Replies
JoeBorgione
MVP Emeritus

My bet is you are trying to use Windows Task Scheduler on a desktop machine with windows 10.  I've never been able to get Task Scheduler to work in that situation; I've only been successful running scheduled tasks on a dedicated server.

That should just about do it....
0 Kudos
Hibby
by
Emerging Contributor

You should be able to.  I am doing the exact same thing with Anaconda on my local desktop machine.  My Python script does the following.

  1. Stop Locator Service on ArcGIS Server
  2. Rebuild locator
  3. Start Locator Service on ArcGIS Server

Jim L.

0 Kudos
AliciaShyu
Frequent Contributor

The script works. What I can't do is make it work in Windows task scheduler to run after hours.

0 Kudos
Hibby
by
Emerging Contributor

I'm assuming you are leaving your machine on.  Try running with the following options enabled:

  • General tab: Run whether user is logged on or not
  • General tab: Run with highest privileges
  • General tab: Configure for: <your_operating_system>
  • Conditions tab: Power -> Wake the computer to run this task

Do you have your Actions setup correctly?

  • Program/script: should reference location of your python.exe
  • Add arguments (optional): should be name of python script
  • Start in (optional): location of your python script.  I use a UNC

Hope this helps

MichaelVolz
Esteemed Contributor

Are you running a bat file that calls multiple python scripts or are all the operations done in 1 python script (stop geocode service, rebuild locator, start geocode service)?  I currently have the Windows Task Scheduler setup to stop geocode services from a Windows 10 desktop, but it only worked the first time I ran it automatically and now it no longer executes the python script automatically so the rebuild address locator fails since there is still a lock on the address locator from the service that did not get stopped.

0 Kudos
AliciaShyu
Frequent Contributor

I'm using one python script and Pro's propy.bat file per ESRI's documentation here Run stand-alone scripts 

I have also tried using the python.exe file in arcgispro-py3 without any success.

 

 

0 Kudos
ShanaBritt
Esri Regular Contributor

There is a reference to a python script in the updated help topic for keeping your locator and geocode service updated with new data https://pro.arcgis.com/en/pro-app/latest/help/data/geocoding/keep-your-locator-up-to-date.htm#ESRI_S.... Perhaps try using the Updating Geocoding Services  script for the scheduled task.

0 Kudos
AliciaShyu
Frequent Contributor

I was able to add the script to task scheduler using the python.exe file in arcgispro-py-clone folder.

I have a clone folder because I had to install some python packages that are not part of Pro. Pro creates a clone folder when you install additional packages. The location of that folder is C:\Users\(user name)\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone

ProCloneFolder.png

0 Kudos
NathanRobbins1
New Contributor

Alicia, I am trying to do the same thing. I have a working script in Python 2.7 and am trying to convert it to Python 3.7 and having problems. Would you be willing to post your working Python 3 script to stop geocoding service, rebuild locator, and start geocoding service?

0 Kudos