I've got a Python script that uses multiprocessing that I need Windows Task Scheduler execute at 6:45 am daily. The reason it is using multiprocessing is so that if the script stalls and has not completed after an hour, the process is terminated.
The script runs perfectly fine when run manually, but when run by Task Scheduler, it skips all code in the function I'm trying to call with multiprocessing. Pseudocode is below.
import arcpy, multiprocessing
set variables
def executeThisFunction():
do work
if __name__ == '__main__':
p = multiprocessing.Process(target=executeThisFunction)
p.start()
#Wait for 3600 seconds (1 hour) or until process finishes
p.join(3600)
#If thread is still active after 3600 seconds
if p.is_alive():
p.terminate()
It's pretty clear that when it's being run via Windows Task Scheduler, my function is being skipped, but when run via Command Prompt or by double-clicking the .py file, everything runs as intended. How do I get around this so that it runs everything in my function when being called from Windows Task Scheduler?