Restart python-script from within itself

前端 未结 9 1885
谎友^
谎友^ 2020-12-02 15:27

I have a python-based GTK application that loads several modules. It is run from the (linux) terminal like so:

./myscript.py --some-flag setting

9条回答
  •  旧巷少年郎
    2020-12-02 16:00

    UPDATE - of the above answer with some example for future reference

    I have runme.sh

    #!/bin/bash
    kill -9 server.py
    python /home/sun/workspace/c/src/server.py &
    

    And i have server.py where i need to restart the application itself, so i had:

    os.system('runme.sh')
    

    but that did not restart the application itself by following runme.sh, so when i used this way:

    os.execl('runme.sh', '')
    

    Then i was able to restart itself

提交回复
热议问题