Script using Python API and Windows task scheduler

289
7
2 weeks ago
AliciaShyu
New Contributor III

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
7 Replies
JoeBorgione
MVP Esteemed Contributor

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.

can't wait to retire....
0 Kudos
Hibby
by
New Contributor II

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
New Contributor III

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

0 Kudos
Hibby
by
New Contributor II

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
New Contributor III

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