|
45 | 45 | # noise in diffs. |
46 | 46 | } |
47 | 47 |
|
48 | | -_mp_plugins: Checkers |
49 | | -_mp_options: argparse.Namespace |
| 48 | +_mp: tuple[Checkers, argparse.Namespace] | None = None |
50 | 49 |
|
51 | 50 |
|
52 | 51 | @contextlib.contextmanager |
53 | 52 | def _mp_prefork( |
54 | 53 | plugins: Checkers, options: argparse.Namespace |
55 | 54 | ) -> Generator[None]: |
56 | 55 | # we can save significant startup work w/ `fork` multiprocessing |
57 | | - global _mp_plugins, _mp_options |
58 | | - _mp_plugins, _mp_options = plugins, options |
| 56 | + global _mp |
| 57 | + _mp = plugins, options |
59 | 58 | try: |
60 | 59 | yield |
61 | 60 | finally: |
62 | | - del _mp_plugins, _mp_options |
| 61 | + _mp = None |
63 | 62 |
|
64 | 63 |
|
65 | 64 | def _mp_init(argv: Sequence[str]) -> None: |
66 | | - global _mp_plugins, _mp_options |
| 65 | + global _mp |
67 | 66 |
|
68 | 67 | # Ensure correct signaling of ^C using multiprocessing.Pool. |
69 | 68 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
70 | 69 |
|
71 | | - try: |
72 | | - # for `fork` this'll already be set |
73 | | - _mp_plugins, _mp_options # noqa: B018 |
74 | | - except NameError: |
| 70 | + # for `fork` this'll already be set |
| 71 | + if _mp is None: |
75 | 72 | plugins, options = parse_args(argv) |
76 | | - _mp_plugins, _mp_options = plugins.checkers, options |
| 73 | + _mp = plugins.checkers, options |
77 | 74 |
|
78 | 75 |
|
79 | 76 | def _mp_run(filename: str) -> tuple[str, Results, dict[str, int]]: |
| 77 | + assert _mp is not None, _mp |
| 78 | + plugins, options = _mp |
80 | 79 | return FileChecker( |
81 | | - filename=filename, plugins=_mp_plugins, options=_mp_options |
| 80 | + filename=filename, plugins=plugins, options=options |
82 | 81 | ).run_checks() |
83 | 82 |
|
84 | 83 |
|
|
0 commit comments