Python Forum
getting a script into the background - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: getting a script into the background (/thread-23268.html)



getting a script into the background - Skaperen - Dec-19-2019

i have done this, before, in C. i'd like to have my script run itself in the background, with the foreground exiting back to the shell. would it be good enough to just have a copy of itself run through the multiprocessing module and have the parent just exit? should i used an intermediary child process? any general suggestions? any pre-written code?

another aspect of this is that ALL other processes for that user will be terminated soon. this could lead to strange effects Python might not be prepared to handle.


RE: getting a script into the background - Larz60+ - Dec-19-2019

I'm guessing that you can't auto run in background since the interpreter will run in foreground.
Only thing I can think of that comes close is running from cron and starting in background


RE: getting a script into the background - Skaperen - Dec-19-2019

the interpreter needs to be in the same process. multiprocessing would call os.fork which would duplicate the process into parent and child. the parent would exit and the child would continue to run. the shell would get SIGCHLD and prompt for the next command. i'm just wondering if there is a more direct way to do that, like something.enter_process_background().