From af2ded663da2fcbc4ce813f7aafbb64fc7906f9c Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 29 Jul 2018 19:21:42 -0700 Subject: [PATCH] fork: public on_fork() function. Generally useful, and needed for ongoing Ansible work. --- mitogen/fork.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mitogen/fork.py b/mitogen/fork.py index 12bb7dfa..cf769788 100644 --- a/mitogen/fork.py +++ b/mitogen/fork.py @@ -75,6 +75,17 @@ def reset_logging_framework(): ] +def on_fork(): + """ + Should be called by any program integrating Mitogen each time the process + is forked, in the context of the new child. + """ + reset_logging_framework() # Must be first! + fixup_prngs() + mitogen.core.Latch._on_fork() + mitogen.core.Side._on_fork() + + def handle_child_crash(): """ Respond to _child_main() crashing by ensuring the relevant exception is @@ -134,10 +145,7 @@ class Stream(mitogen.parent.Stream): handle_child_crash() def _child_main(self, childfp): - reset_logging_framework() # Must be first! - fixup_prngs() - mitogen.core.Latch._on_fork() - mitogen.core.Side._on_fork() + on_fork() if self.on_fork: self.on_fork() mitogen.core.set_block(childfp.fileno())