bjoern
bjoern copied to clipboard
fork example ignores child processes exit code
The fork example (https://github.com/jonashaag/bjoern/blob/master/tests/fork.py) ignores child processes' exit codes. Whatever happens to the children, the parent process will exit gracefully. This does not allow to run it with supervisord or similar means (which automatically restart crashed processes).
Additionally, the fork example will allow a situation when (on a multi-CPU machine) half of child processes crashed for some reason, the other half is still alive, and the server is thus underperforming (not utilizing all CPU cores).
I personally reworked the end of the file like this:
try:
# Wait for the first worker to exit. They should never exit!
# Once first is dead, kill the others and exit with error code.
pid, xx = os.wait()
worker_pids.remove(pid)
finally:
for pid in worker_pids:
os.kill(pid, signal.SIGINT)
exit(1)
I guess we should rather re-spawn the children?
That should work, too.
OK, feel free to submit a patch!