-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
[subinterpreters] _PyImport_FixupExtensionObject() regression in Python 3.9 #88216
Comments
This issue is a regression in Python 3.9. It was recently fixed in main/3.10, but I'm opening this issue to request that it is fixed in 3.9 as well since it breaks certain Python scripts running in WeeChat. I have a C application which is using the Python/C API and is running multiple python subinterpreters. One of those subinterpreters is running a script which is reading data from a non-blocking ssl socket. When there is no more data to read, trying to read throws This is a regression in 3.9. It didn't happen in 3.8. The commit that introduced the issue is 82c83bd I have attached a C program to reproduce the issue. It seems I can only attach one file per comment, so the python script that program runs will follow in the next commit. It connects to an ssl socket, so you need to have that running first. That can be started by running this:
The script will output this when the issue is not present (so in 3.8 and main):
And this when the issue is present (in 3.9):
|
Here is the Python script that the C program to reproduce the issue runs. |
And here are the bug reports for two Python scripts that are affected by this issue: |
Right, the _ssl module was ported to multiphase initialization (PEP-489) in bpo-42333 (fixed in Python 3.10.0a3).
In Python 3.9, some stdlib modules are still using the legacy API to initialize modules, and share states between interpreters. This is bad: no Python object (nor state) must be shared between two interpreters. Well, there is an on-going work on subinterpreters:
For example, many C extensions are being converted to the multiphase initialization API and get a "module state". The _PyImport_FixupExtensionObject() change impacts extensions using the legacy API and so should not be used in subinterpreters. Maybe the old behavior was better: if an extension uses the old API, share its state between all interpreters. |
I'm not using that directly in my code, but I guess it's used indirectly? If it shouldn't be used, what's the alternative in 3.9?
Since this worked fine as far as I know before 3.9, and currently breaks existing applications, this is probably better yes. |
I just took a look at this, and I'm getting an output of "no data" (just one time) on 3.9.6. Has this been fixed? |
@jack__d: If you're just getting "no data" once and nothing else, the test isn't working correctly. You should get "no data" twice when it works correctly and the issue is fixed, or "unknown error" and some other info if the issue is present. I'm not sure why it doesn't work for you though. I tried it with Python 3.9.6 now, and I'm still seeing the issue, with the same output as in my original post (apart from a newline between "no data" and "unknown error", and a different line number and id numbers). |
Yes, I think the old behavior was better: if an extension uses the old API, share its state between all interpreters. This is obviously bad, but I don't see how skipping part of initialization (as done in 82c83bd#diff-28cfc3e2868980a79d93d2ebdc8747dcb9231f3dd7f2caef96e74107d1ea3bf3L721-R719 ) is better. |
Make Sense. It's more better and exact than my suggestion :) |
Thanks for the fix. I don't understand well this code :-( |
Thanks, Hai Shi! ✨ 🍰 ✨ |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: