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
Misleading __reduce_cython__ error on import #3545
Comments
I'm not so sure. This ticket is about a programming error, and pretty much all cases I've seen so far seemed to involve pip installations or some kind of build setup problem instead. Specifically, whenever a module reloading attempt is involved, this error can occur. There's this code these days: cython/Cython/Compiler/ModuleNode.py Lines 2676 to 2689 in fcb4403
So we already raise an exception on attempts to import a module twice, and prevent re-initialising the same module instance more than once. I can't say right now why these two cases don't produce a better error message (or actually work) in your case. Investigation welcome. It could actually be that attempts to re-initialise the module come after first clearing the module dict. That would (obviously) break things, and if that's the case, then we need to find a way to actually rebuild the module dict. Or, more simply, always raise an exception on re-initialisation attempts. (Or keep track of full init-clear cycles, or something like that.) |
I already ran into this issue two or three times myself, but not yet with one of the Cython 3.0 alpha releases, so no comment about the module loading/reinitialization improvements yet. |
@Timtam If you have an example of the code that caused this error then it'd be useful. The example given in this issues had too many external dependencies for me to get it to run so something a bit simpler and easier to diagnose would definitely be good (if it exists) |
I don't have an example right now, but I might be able to put one together if I don't forget about it and find the time to do so. I'll comment if I found something out. |
Right: I have a simple reproducible 2-file example of this error:
mod1 can be compiled with
Running
|
Could be due to dead code removal when the last statement is known to raise, i.e. when there is no success return case. |
@da-woods hmm, I tried your example in Py3.[678] with latest master but got the expected (chained) |
Ah. I think I was testing it on the 0.29 branch. You're right - it seems OK in master. It's clearly harder to reproduce than I thought |
@scoder Move the exception before the class definition and it does break in master though. I've edited the example above |
…porting an extension module that was already initialised before. Closes #3545.
Let's see if #3549 resolves this. |
* Work around error that "__reduce_cython__ cannot be found" when re-importing an extension module that was already initialised before. * Exclude "reimport_failure" test in Py2 and PyPy since Py2 does not allow reimports and PyPy3 apparently does nothing for them. Closes #3545.
…porting an extension module that was already initialised before. Backport to 0.29.x. Closes #3545.
…porting an extension module that was already initialised before. Backport to 0.29.x. Closes #3545.
Thanks for the report @dvarrazzo and for the stripped down test case @da-woods. |
Confirmed fixed for my use case too. Thank you for working on it even if my test wasn't easy to reproduce! 👍 |
Whenever you use an
import
instead of acimport
compiling will work but you might be graced with an unrelated error message at import time.Can't create easily a self-contained test: I tried and the code was failing with an expected
ImportError
, however you can reproduce it it with:Which raises the error:
I believe many help requests about
__reduce_cython__
are related to this.Tested with Python 3.6 and Cython 3.0a1.
The text was updated successfully, but these errors were encountered: