HOW TO

Automate ArcGIS Pro launch and shutdown to refresh license token during Python task automation

Last Published: December 16, 2024

Summary

In ArcGIS Pro, when using the Named User license, the license token expires every 15 days, which affects the Python scripts or tasks fail to run once the token expires. For more information, refer to ArcGIS Developers: Request parameters. To avoid this, the Named User license must be refreshed by manually launching ArcGIS Pro before the token expires.

This article demonstrates the workflow to automate the ArcGIS Pro launch and shutdown to refresh the license token during a Python task automation.

Note:
Before automating Python scripts or tasks with ArcPy, ensure there is valid access to the ArcGIS Pro license by signing in with a licensed account or using a license file.

Procedure

  1. Launch the Python command line interface or Python IDLE window. In this example, the Python IDLE window is launched.
  2. Copy and paste the following script. Edit the timer and ArcGIS Pro's file path accordingly.
Note:
The indentations must be maintained in the script.
  1. The script uses subprocess, time, and threading modules to manage external processes, delays, and concurrent execution.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess, time, threading
  1. Set a countdown timer in seconds.
timer:int=25
  1. A variable to store the subprocess object representing ArcGIS Pro.
arcgispro = None
  1. The counter_ function displays a countdown timer, providing real-time feedback as ArcGIS Pro launches.
def counter_():
    print("ArcGIS Pro Opening...")
    for i in range(timer - 1, 0, -1):
        time.sleep(1)
        print(i)
  1. Start and close ArcGIS Pro after the countdown.
def openArcGISPro_reset():
    try:
        global arcgispro
        arcgispro = \
            subprocess.Popen([r"C:\Users\<username>\AppData\Local\Programs\ArcGIS\Pro\bin\ArcGISPro.exe"])
        time.sleep(timer)
        arcgispro.terminate()
    except Exception as e:
        print(e)
  1. Start a new thread to execute the counter_ function concurrently.
threading.Thread(target=counter_).start()
Note:
Once the countdown reaches 1, press Enter.
  1. The openArcGISPro_reset() function runs in the main thread and starts or terminates ArcGIS Pro.
openArcGISPro_reset()

The code block below demonstrates the full working script.

#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess, time, threading

timer:int=25

arcgispro=None

def counter_():
    print("ArcGIS Pro Opening...")
    for i in range(timer - 1, 0, -1):
        time.sleep(1)
        print(i)

def openArcGISPro_reset():
    try:
        global arcgispro
        arcgispro = \
            subprocess.Popen([r"C:\Users\<username>\AppData\Local\Programs\ArcGIS\Pro\bin\ArcGISPro.exe"])
        time.sleep(timer)
        arcgispro.terminate()
    except Exception as e:
        print(e)

threading.Thread(target=counter_).start()

openArcGISPro_reset()

The image below shows ArcGIS Pro automatically resetting after running the script.

The image of ArcGIS Pro resetting after the script is run.

Article ID: 000033675

Software:
  • ArcGIS Pro 3 3
  • ArcGIS Pro 3 2
  • ArcGIS Pro 3 4

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options