-
-
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
asyncio with two interpreter instances #91375
Comments
Hi, _asynciomodule.c:
get_running_loop(PyObject **loop)
{
PyObject *rl;
PyThreadState *ts = _PyThreadState_GET();
uint64_t ts_id = PyThreadState_GetID(ts);
if (ts_id == cached_running_holder_tsid && cached_running_holder != NULL) { If it does not make sense, I have some sample code but it is not just 10 lines. |
hello, is there anything we can do to get some attention ? Thanks in advance |
It looks like asyncio has not been updated to support use in multiple interpreters -- the module uses a whole bunch of global variables to store state. Until that is dealt with, asyncio cannot be used reliably with multiple interpreters. See PEP 687. @erlend-aasland Also note that this is unlikely to be considered a bug, so no backports. Likewise it is unlikely to happen for 3.11 since the feature freeze is literally today. Thus the soonest you may see a fix is 3.12 (Fall 2023), unfortunately. |
Yeah, as soon as PEP 687 land, we can start the process of implementing this. I believe I've got a WIP branch lying around already. |
Thanks for the update, we will be patient. just a shame not to have back port, but understood the amount of work. Potential testing platforms OS: raspian or fedora |
I can push it to my fork next week, so you can play with it. |
One workaround currently is to not use |
interesting. How to you prevent using _asyncio ? |
Before importing import sys
sys.modules["_asyncio"] = None |
@kumaraditya303 if ayncio is imported in many module. does it enough to do it only once while importing asyncio for the first time ? [edit] at least I did it prior the first occurence of import and this looks pretty good . |
Yes it is only required once when |
@kumaraditya303 big big big thanks. This is an awesome workaround . |
Since PEP 687 is accepted, how about it? Seems a good idea to get this out of the way. |
Also, looking at the code a bit more, it looks like |
Thanks for the ping. I'll try to find time for this in the coming week. |
That would work. We would use the existing An alternative would be to rely on That said, once _asynciomodule.c has been updated, the |
@erlend-aasland Did you ever get to this? It reared its head again. |
Sorry; for various reasons I haven't been able to devote much time to CPython the last weeks. I picked up my work on this last week, though. Currently, the diff stat is ±500 lines, but I expect it to double or tiple by the time I'm done (there'll be some clinic changes that will explode the diff). I also got a ref. leak after converting TaskType to heap type. It's been time-consuming to debug it on my machine; a I'll create a draft PR so anyone interested can join in and help with debugging and progress. |
Looking forward to the draft PR. Thanks
Debugging on Linux is much faster so I will be able to debug it faster. |
FTR, here's my WIP branch: https://github.com/erlend-aasland/cpython/tree/isolate-asyncio |
Draft PR here #99122 |
…#99122) Co-authored-by: Erlend E. Aasland <[email protected]>
Thanks for working on this, @kumaraditya303! |
Reopening: the future iter object freelist is still a static global, and we forgot to clean up |
I left that freelist intentionally as it is not an issue until we have per interpreter GIL. @markshannon has ideas for a global better freelist so hopefully we should be able to remove this freelist entirely. |
I see, thanks for the heads-up. |
Hm. I wouldn't necessarily count on Mark's single freelist idea to be implemented before we get a per-subinterpreter GIL (esp. since the work on mimalloc seems stalled, alas -- Christian Heimes seems to be occupied by other things). So I think it would behoove us to move |
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:
_asyncio
static types to heap types and module state #99122The text was updated successfully, but these errors were encountered: