Restarting a self-updating python script

前端 未结 8 790
小鲜肉
小鲜肉 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 19:08

    Main File:

    if __name__ == '__main__':
    
    if os.path.isfile('__config.py'):
        print 'Development'
        push.update_server()
    else:
        e = update.check()
        if not e: sys.exit()
    

    Update File:

    def check():
        e = 1.....perform checks, if something needs updating, e=0;
        if not e:
            os.system("python main.pyw")
        return e
    

    Here's the logic:

    Main program calls the update function

    1) If the update function needs to update, than it updates and calls a new instances of "main"

    Then the original instance of "main" exits.

    2) If the update function does not need to update, then "main" continues to run

提交回复
热议问题