Skip to content

Fix multiprocessing warnings when runnign tests on Python 3.12 #16564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Nov 25, 2023

I saw a bunch of warnings when running tests in parallel using pytest. When running tests sequentially using -n0 I didn't see warnings. This only seems to happen on Linux.

The warnings were like these, which can be fixed by avoiding the use of fork, and using forkserver instead:

mypy/test/teststubgen.py::StubgenPythonSuite::stubgen.test::testNestedClass_inspect
  /usr/local/lib/python3.12/multiprocessing/popen_fork.py:66: DeprecationWarning: This process (pid=84587) is multi-threaded, use of fork() may lead to deadlocks in the child.
    self.pid = os.fork()

Relevant discussion:
https://discuss.python.org/t/concerns-regarding-deprecation-of-fork-with-alive-threads/33555

I saw a bunch of warnings when running tests in parallel using pytest.
When running tests sequentially using `-n0` I didn't see warnings. This
only seems to happen on Linux.

The warnings were like these, which can be fixed by avoiding the use of fork,
and using forkserver instead:
```
mypy/test/teststubgen.py::StubgenPythonSuite::stubgen.test::testNestedClass_inspect
  /usr/local/lib/python3.12/multiprocessing/popen_fork.py:66: DeprecationWarning: This process (pid=84587) is multi-threaded, use of fork() may lead to deadlocks in the child.
    self.pid = os.fork()
```

Relevant discussion:
https://discuss.python.org/t/concerns-regarding-deprecation-of-fork-with-alive-threads/33555
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pyp (https://github.com/hauntsaninja/pyp): typechecking got 6105.34x slower (0.0s -> 11.5s)
(Performance measurements are based on a single noisy sample)

discord.py (https://github.com/Rapptz/discord.py): typechecking got 1.09x faster (190.9s -> 174.9s)
(Performance measurements are based on a single noisy sample)

@JukkaL JukkaL merged commit 379d59e into master Nov 27, 2023
@JukkaL JukkaL deleted the fix-3.12-warnings branch November 27, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants