Files
pytorch/torch/multiprocessing/_atfork.py
Xuehai Pan f3fce597e9 [BE][Easy][17/19] enforce style for empty lines in import segments in torch/[a-c]*/ and torch/[e-n]*/ (#129769)
See https://github.com/pytorch/pytorch/pull/129751#issue-2380881501. Most changes are auto-generated by linter.

You can review these PRs via:

```bash
git diff --ignore-all-space --ignore-blank-lines HEAD~1
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/129769
Approved by: https://github.com/ezyang
2024-08-04 10:24:09 +00:00

36 lines
790 B
Python

# mypy: allow-untyped-defs
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)