Restarting a self-updating python script

前端 未结 8 771
小鲜肉
小鲜肉 2020-11-30 18:48

I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.

I am not sure what the

8条回答
  •  甜味超标
    2020-11-30 18:59

    In Linux, or any other form of unix, os.execl and friends are a good choice for this -- you just need to re-exec sys.executable with the same parameters it was executed with last time (sys.argv, more or less) or any variant thereof if you need to inform your next incarnation that it's actually a restart. On Windows, os.spawnl (and friends) is about the best you can do (though it will transiently take more time and memory than os.execl and friends would during the transition).

提交回复
热议问题