-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
crash if asyncio is used before and after re-initialization if using python embedded in an application #89425
Comments
We have embedded Python in our application and we deinitialize/initialize the interpreter at some point of time. If a simple script with a thread that sleeps with asyncio.sleep is loaded before and after the re-initialization, then we get the following assertion in the second run of the python module: "Assertion failed: Py_IS_TYPE(rl, &PyRunningLoopHolder_Type), file D:\a\1\s\Modules_asynciomodule.c, line 261" Example to reproduce this crash: https://github.com/benjamin-sch/asyncio_crash_in_second_run |
I guess the fix requires switching C Extension types from static to heap for _asyncio module. We need a champion for the issue. |
The _asyncio extension uses static types and doesn't implement the multiphase initialization API. It doesn't work well with your "deinitialize/initialize the interpreter" use case. The _asyncio extension should use heap types and the multiphase init API. |
We were hitting the same issue in kodi, which uses embedded sub-interpreters to run python addons, after one of the addons was switched to asyncio. The immediate cause of the assertion failure is a use-after-free issue from the running loop holder cache: When the running loop holder is deallocated (which happens eg on interpreter shutdown) cached_running_holder holds a dangling pointer. A subsequent call to get_running_loop() may then pick that up and boom. While probably not a full fix for this issue I think it would be good to fix the use-after-free problem - there could be other code paths that lead to this situation. I've created a github pull request for that |
Is Matthias Reichl's fix enough to use asyncio in a subinterpreter? |
The original issue was fixed, hence closing if there are more issue you can create new issue for it. |
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: