bjoern icon indicating copy to clipboard operation
bjoern copied to clipboard

fork example ignores child processes exit code

Open IlyaSemenov opened this issue 6 years ago • 3 comments

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)

IlyaSemenov avatar Jan 23 '18 12:01 IlyaSemenov

I guess we should rather re-spawn the children?

jonashaag avatar Jan 23 '18 12:01 jonashaag

That should work, too.

IlyaSemenov avatar Jan 23 '18 12:01 IlyaSemenov

OK, feel free to submit a patch!

jonashaag avatar Jan 23 '18 12:01 jonashaag