Strange os.execl() behavior when python is run from the windows cmd line -
i'm experiencing unexpected behavior os.execl on windows python 3.3.2 (this may apply in other places, environment i've attempted in). goal in example able restart running program on keyboardinterrupt. code:
import os import sys import time def main(): print("welcome.") while true: try: print("hello.") time.sleep(10) except keyboardinterrupt: break args = sys.argv args[0] = '"' + args[0] + '"' # should restart program. os.execl(sys.executable, sys.executable, * args) if __name__ == '__main__': main() when run program double clicking on .py file, , keyboard interrupt, goes expected. program restarts, , see second welcome message. can number of times without issue.
when run via command line (either typing python myprog.py or myprog.py), funky things seem happen. upon issuing keyboardinterrupt, program seems stop without restarting. when in task manager, curiously still see python.exe running. if run program again command line, immedieately see:
welcome hello welcome hello if keyboardinterrupt out of again, see 2 rogue python.exe processes sitting in task manager. sure enough if run third time command line, see 3 welcome/hello messages.
would love know if expected behavior, or if there's else need doing make running command line work in situation?
Comments
Post a Comment