|
|
Question : Start a process, then die without also killing the (child) process that was started
|
|
Hi,
I have a python script which logs in to our game server and acts like a normal player, starting a game and waiting for a user to join. The idea is that every time a game is started, the script runs a command so that a new script is started, and thus another "robot" player logs in. Whenever a game is finished, the process dies. The effect of this is that there should always be one robot player waiting to play. My problem is this:
Using os.popen2('python script.py'), that script is started as a child process. That means that when the parent dies, so does the child.
How can I work around this?
I can see some possible options, but I need some hints code-wise:
1. Somehow start the process as a completely seperate process, not a child one. I believe php's "exec" function works like this, but I can't find any equivalent in python. 2. Somehow kill the process making sure that the children are not killed.
Any ideas?
|
Answer : Start a process, then die without also killing the (child) process that was started
|
|
AFAIR when parent ends it sends SIGHUP to all children, so just process it and ignore:
from signal import signal, SIGHUP, SIG_IGN signal(SIGHUP, SIG_IGN)
|
|
|
|
|