FastAPI - need to asyncio.sleep() or event is not even emitted #1093
-
I am trying to implement a logic similar to this using async client and fastAPI+socketio server. After a lot of try/fail I found that an Cannot understand what is it going on here, any help appreciated.
(complete code/requirements and log dump available on request) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You are using a I don't understand why are you mixing a threading.Event in your async application. Asyncio has event objects, why not use those? |
Beta Was this translation helpful? Give feedback.
You are using a
threading.Event
with asyncio, which does not really make sense, since it is blocking. Theev.wait()
is going to block the asyncio loop, preventing all the background activity from Socket.IO from happening (along with everything else that goes on in your application). The sleep gives you the impression that it addresses the problem only because during that 0.1 of a second the background work needed by the emit is completed. But you are still blocking the loop right after.I don't understand why are you mixing a threading.Event in your async application. Asyncio has event objects, why not use those?