We just migrated Python scripts running on an old Windows 7 VM to a Windows 10 VM. Most of them worked just fine, but one script that ends with the following statement hangs when run from Task Scheduler.
sys.exit(0 if successful else 1)
If I run it from the command line or IDLE, it completes just fine. It only hangs as a scheduled task. I added print statements on every line at the end and the only one that doesn't execute is the one after sys.exit. So either it is hanging on sys.exit in Python or Task Scheduler is having an issue after the script finishes. This only happens in the script where I have a sys.exit call. I added it to let me know if the script had any errors in it. I catch any exceptions in the script and add them to an email notification, so the script normally ends with return code 0 if I don't do this. I can imagine some workarounds, but I wanted to see why it no longer works anymore. Any one else have experience with this?