Skip to content

Disable parallel cythonization for "spawn" start method.#3263

Merged
scoder merged 2 commits intocython:masterfrom
mbargull:fix-cythonize-multiprocessing-spawn
Aug 30, 2025
Merged

Disable parallel cythonization for "spawn" start method.#3263
scoder merged 2 commits intocython:masterfrom
mbargull:fix-cythonize-multiprocessing-spawn

Conversation

@mbargull
Copy link
Copy Markdown
Contributor

@mbargull mbargull commented Dec 6, 2019

Resolves gh-3262.

I have not looked into Cython's test framework.
An integration test that runs a small script like the following would work:

#cython: language_level=3

from multiprocessing import set_start_method
set_start_method("spawn", force=True)

from Cython.Build import cythonize
cythonize([__file__] * 2, nthreads=1)

@samuelcolvin
Copy link
Copy Markdown
Contributor

Surely better to have a warning or error to alert people to this?

@mbargull
Copy link
Copy Markdown
Contributor Author

mbargull commented Dec 6, 2019

Thanks for taking a look @samuelcolvin!

@scoder
Copy link
Copy Markdown
Contributor

scoder commented Apr 30, 2020

I think it's ok as it is, just needs to work on Py2.7 as well, which lacks mp.get_start_method().

@mLewisLogic
Copy link
Copy Markdown

Just hit this error trying to enable multiple nthreads. Would be nice to mainline.

@scoder
Copy link
Copy Markdown
Contributor

scoder commented Oct 4, 2020

See my comment just above.

@mLewisLogic
Copy link
Copy Markdown

Ya, recognize that's a blocker. Just sharing user experience (from somebody running 3.8).
A search for the exact error led me to this issue, otherwise debugging it would have been a rabbit hole.

@da-woods
Copy link
Copy Markdown
Contributor

da-woods commented Oct 4, 2020

Presumably it'd do to check for sys.platform == "win32" instead on Python 2.7

@scoder
Copy link
Copy Markdown
Contributor

scoder commented Oct 4, 2020

Presumably …

Well, yes, maybe. There is no regression test for this, so I can't tell.

@jakeschurch
Copy link
Copy Markdown

jakeschurch commented Sep 4, 2023

this seems to fix issues im seeing currently on my machine when added as patch. What's blocking getting this merged? Is this anything I can help with?

@jakeschurch
Copy link
Copy Markdown

I think it's ok as it is, just needs to work on Py2.7 as well, which lacks mp.get_start_method().

@scoder what is cython's bugfix policy for python2 bugs? For Python I know the sunset date for any more bugfixes on python 2 was Jan 1, 2020. Surely this isn't a blocker?

@jakeschurch
Copy link
Copy Markdown

we could also guard check with sys.version_info >= (3, 8)

@scoder scoder added this to the 3.2 milestone Aug 30, 2025
@scoder scoder merged commit 1a4f6a7 into cython:master Aug 30, 2025
79 checks passed
@scoder
Copy link
Copy Markdown
Contributor

scoder commented Aug 30, 2025

Thanks. Sorry it took so long.

@webknjaz
Copy link
Copy Markdown
Contributor

webknjaz commented Oct 1, 2025

So while this took care of Cython/Build/Dependencies.py, the same problem exists in Cython/Build/Cythonize.py. It should be patched the same.

webknjaz added a commit to webknjaz/cython that referenced this pull request Oct 1, 2025
A similar problem was fixed in cython#3263 which is what this patch is
porting to another module. That fixed the Python-land API while this
change aims to also fix its command-line counterpart.

The symptoms are Python 3.8+, macOS and the underlying compiler
invocations failing. If these are met, `cythonize` would hang before
this commit.

Fixes cython#3973.

Refs:
* cython#3262
* cython#7146
* ansible/pylibssh#769
@webknjaz
Copy link
Copy Markdown
Contributor

webknjaz commented Oct 1, 2025

#7183 should complete the fix started in #3263.

webknjaz added a commit to webknjaz/cython that referenced this pull request Oct 4, 2025
A similar problem was fixed in cython#3263 which is what this patch is
porting to another module. That fixed the Python-land API while this
change aims to also fix its command-line counterpart.

The symptoms are Python 3.8+, macOS and the underlying compiler
invocations failing. If these are met, `cythonize` would hang before
this commit.

Fixes cython#3973.

Refs:
* cython#3262
* cython#7146
* ansible/pylibssh#769
webknjaz added a commit to webknjaz/cython that referenced this pull request Oct 8, 2025
A similar problem was fixed in cython#3263 which is what this patch is
porting to another module. That fixed the Python-land API while this
change aims to also fix its command-line counterpart.

The symptoms are Python 3.8+, macOS and the underlying compiler
invocations failing. If these are met, `cythonize` would hang before
this commit.

Fixes cython#3973.

Refs:
* cython#3262
* cython#7146
* ansible/pylibssh#769
@jakeschurch
Copy link
Copy Markdown

no worries - i really appreciate it!

webknjaz added a commit to webknjaz/cython that referenced this pull request Oct 10, 2025
A similar problem was fixed in cython#3263 which is what this patch is
porting to another module. That fixed the Python-land API while this
change aims to also fix its command-line counterpart.

The symptoms are Python 3.8+, macOS and the underlying compiler
invocations failing. If these are met, `cythonize` would hang before
this commit.

Fixes cython#3973.

Refs:
* cython#3262
* cython#7146
* ansible/pylibssh#769
scoder added a commit to scoder/cython that referenced this pull request Oct 21, 2025
A similar problem was worked around in cython#3263
by disabling parallelism altogether.  This patch reverts that and updates the worker
management to use concurrent.futures.ProcessPoolExecutor instead of multiprocessing.Pool.

The symptoms are Python 3.8+ and the underlying compiler invocations failing.
If these are met, cythonize would hang before this commit.

Original PR by Sviatoslav Sydorenko in cython#7183

Fixes cython#3973

See cython#3262
See cython#7146
scoder added a commit that referenced this pull request Oct 21, 2025
A similar problem was worked around in #3263
by disabling parallelism altogether.  This patch reverts that and updates the worker
management to use concurrent.futures.ProcessPoolExecutor instead of multiprocessing.Pool.

The symptoms are Python 3.8+ and the underlying compiler invocations failing.
If these are met, cythonize would hang before this commit.

Original PR by Sviatoslav Sydorenko in #7183

Fixes #3973

See #3262
See #7146
scoder added a commit that referenced this pull request Oct 21, 2025
A similar problem was worked around in #3263
by disabling parallelism altogether.  This patch reverts that and updates the worker
management to use concurrent.futures.ProcessPoolExecutor instead of multiprocessing.Pool.

The symptoms are Python 3.8+ and the underlying compiler invocations failing.
If these are met, cythonize would hang before this commit.

Original PR by Sviatoslav Sydorenko in #7183

Fixes #3973
Closes #7183

See #3262
See #7146
scoder added a commit that referenced this pull request Oct 23, 2025
A similar problem was worked around in #3263
by disabling parallelism altogether.  This patch reverts that and updates the worker
management to use concurrent.futures.ProcessPoolExecutor instead of multiprocessing.Pool.

The symptoms are Python 3.8+ and the underlying compiler invocations failing.
If these are met, cythonize would hang before this commit.

Original PR by Sviatoslav Sydorenko in #7183

Fixes #3973
Closes #7183

See #3262
See #7146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle cythonize(..., nthreads=1) for "spawn" start method

7 participants