Bring the current Python program to background

前端 未结 2 1494
野的像风
野的像风 2021-02-01 18:21

A python script prints information to screen and then should go to background.

How to do that from within the script itself?

2条回答
  •  佛祖请我去吃肉
    2021-02-01 19:26

    Update: To properly daemonize your process, use daemonize.

    Original answer: Since the shell is waiting for your process to finish, the main process must terminate. You can use os.fork() to fork off a child process and sys.exit() from the parent process:

    import os
    import sys
    
    if os.fork():
        sys.exit()
    # Child code goes here
    

提交回复
热议问题