Skip to content

Commit

Permalink
fork: public on_fork() function.
Browse files Browse the repository at this point in the history
Generally useful, and needed for ongoing Ansible work.
  • Loading branch information
dw committed Jul 30, 2018
1 parent 3e0de97 commit af2ded6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions mitogen/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -134,10 +145,7 @@ def _wrap_child_main(self, childfp):
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())
Expand Down

0 comments on commit af2ded6

Please sign in to comment.