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
Update module setup code for free-threaded CPython #6137
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a nogil-CPython test job, so we're currently running rather blind on this configuration.
Cython/Utility/ModuleSetupCode.c
Outdated
#elif defined(Py_GIL_DISABLED) || defined(Py_NOGIL) | ||
#elif defined(Py_NOGIL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the nogil fork is merged, it probably makes sense to treat it as a special case of CPython. The risky sections that we used to hide under the …IN_CPYTHON
macro should long have received their own special macro (like USE_BORROWED_REFS
etc.).
Correct. I can work on adding CI for nogil-CPython if you want, but that will probably fail for a while. Also, |
Cython/Utility/ModuleSetupCode.c
Outdated
#ifdef Py_GIL_DISABLED | ||
#define CYTHON_COMPILING_IN_NOGIL 1 | ||
#else | ||
#define CYTHON_COMPILING_IN_NOGIL 0 | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit risky. Currently, there is only ever one CYTHON_COMPILING_IN…
macro set to 1, which makes "if-elif-else" special cases easy to write and follow. I'd rather rename this to distinguish it from the "main" target environment (which continues to be CPython here).
OTOH, "compiling in" is pretty accurate, and seeing a name like CYTHON_IN_CPYTHON_NOGIL
would make me wonder if someone just forgot the COMPILING
part there.
Maybe CYTHON_COMPILING_IN_CPYTHON_NOGIL
would be ok as a compromise? That would at least link it to the CPYTHON
macro. I'll be happy to read better suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CYTHON_COMPILING_IN_CPYTHON_NOGIL
sounds good to me.
When I compile cython itself on this branch, I see warnings like
|
That probably is unrelated. The Limited API work introduces some error checking that's skipped for non-limited API operations. That'll add some unused paths on the non-limited API mode. At some point we're going to need to clean up the warnings from those. Edit: unrelated |
A few months ago @colesbury asked to keep the old My proposal would be to treat them as two unrelated products and have a separate define for each. So leave the old code as is (maybe renaming to |
FWIW, I think we can now drop the old I think we should be able update scikit-learn's continuous build soon, and in the meantime I'm already maintaining out-of-tree patches and can continue to do so. |
Thanks - I'm happy for it to be dropped then. |
Regarding the CI job, it probably makes more sense to keep it in a separate fork, right? I assume it'll fail a lot over the next few weeks, and it probably wouldn't be a good idea to always have a red CI. |
The Py3.13 jobs have |
Any further comments on this? Lysandros is on vacation for the next week or two but he's asked me to help make sure this gets merged. |
Thanks |
Trying to build Cython (and run the test suite) with the latest CPython main with
--disable-gil
leads to segfaults. The following patch fixes the segfaults. Running the test suite with-X gil=1
(GIL enabled, default) succeeds locally on my machine, while running it with-X gil=0
(GIL disabled) fails with 8 test failures, all related torefnanny
.I'm opening this PR to see whether these changes really make sense (probably first time where there's two
CYTHON_COMPILING_IN_*
flags enabled) and I'll look into the failures as well, if that's okay. Also, NumPy builds under the free-threaded build with these changes.