File size: 795 Bytes
b2659ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys

__all__ = ["register_after_fork"]

if sys.platform == "win32":
    import multiprocessing.util as _util

    def _register(func):
        def wrapper(arg):
            func()

        _util.register_after_fork(_register, wrapper)

else:
    import os

    def _register(func):
        os.register_at_fork(after_in_child=func)


def register_after_fork(func):
    """Register a callable to be executed in the child process after a fork.



    Note:

        In python < 3.7 this will only work with processes created using the

        ``multiprocessing`` module. In python >= 3.7 it also works with

        ``os.fork()``.



    Args:

        func (function): Function taking no arguments to be called in the child after fork



    """
    _register(func)