task completion handling in asyncio.run_until_complete() #16748
Unanswered
yoctopuce
asked this question in
Core Development
Replies: 2 comments 2 replies
-
It's not clear to me whether there are circumstances where this would affect normal code. If you can produce a simple repro demonstrating a bug, I suggest raising an issue. |
Beta Was this translation helpful? Give feedback.
1 reply
-
If I understand correctly, maybe you could use one more 'main_task' to manipulate each task like you want... |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First a bit of context: as part of my implementation of a MicoPython code debugger, I have implemented an asyncio task inspector. In order to do so, I have instrumented functions
task_make_new
andtask_attr
inmodasyncio.c
to track creation and completion using a C callback hook.I have noticed today that whenever a task is run via run_until_complete, the task object was not properly marked as done, possibly causing strange side effects.
Looking at
asyncio/core.py
, I see that indeed, when the so-called main task is done, the function exits before handling the task state:I was able to fix my problem by setting
t.state
toFalse
just after clearingcur_task
, but I was wondering if the proper fix might involve a bit more than that. In particular, I wonder ift.state
could possibly be a task queue, that should be pushed to the global_task_queue
for proper continuation later on. In the most common case whererun_until_complete
is invoked as a unique entry point, this would not be necessary, but there are other cases whererun_until_complete
could be used in more subtle ways.What do you think ?
Beta Was this translation helpful? Give feedback.
All reactions