I’ve been encountering similar issues. I have found that ArcGIS Pro (which we license through AGOL) automatically logs itself out of every 90 days. I have many Arcpy scripts running via Task Scheduler 24/7.
Also, periodically (usually once a day at a specific time) scripts will fail saying “RuntimeError: The Product License has not been initialized.” No idea what is causing this error as this script runs all day every 30 mins and never gets this error the rest of the day.
ESRI Tech Support sent me this suggestion which we have yet to implement…
-------------------------------------------
We’ve done a bit of digging into our documentation and might have a solution for you. The bad news is, it doesn’t look like there’s a good way to handle the Pro license refresh through Python. The good news is, there is a promising option for handling it in your environment directly. Please see below for a configuration step-by-step that should solve your logout issue:
Step 1: Environmental settings
- Convert your Named license to a Single Use license for this instance of Pro (if you haven’t already). See https://pro.arcgis.com/en/pro-app/latest/get-started/convert-named-user-licenses-to-single-use.htm for more details on how to configure this. This should allow offline access for Pro.
- Make sure “Sign me in automatically” remains checked when you log into Pro on this machine. Just in case.
Step 2: Caching local user (src: https://community.esri.com/t5/python-questions/arcpy-fails-to-import-when-not-logged-into-host-machi...)
- Log into the server that will host the script using the username that will be running the script (i.e. the “owner” in task scheduler).
- Once logged in, open ArcGIS Pro (this will create an esri profile cookie in your AppData folder, that ArcGIS will be able to use to recognize the user).
- Make sure your license and configurations are set according to step 1 and close Pro.
Step 3: Just in case… (src: https://community.esri.com/t5/arcgis-pro-questions/running-a-scheduled-task-on-a-server-machine/m-p/...)
- If the issue persists after running through steps 1 and 2, it means that your Pro configuration requires the application to be open while running scripts against its library, for whatever reason. If this is the case, and only after completing steps 1 and 2, we recommend you include a task before the script in your task scheduler that will open ArcGIS Pro, to remove any weird library locks. This is an edge case but does appear to affect some users, so I wanted to include it in the outline.