python-socketio: can two AsyncClient run in the same asyncio loop? #1673
Replies: 2 comments 4 replies
-
Sorry about the bad discussions link, it should have directed you to the discussions on the other repository, I just corrected it. The sio1.connect(...)
sio2.connect(...)
sio1.wait()
sio2.wait() I haven't tested this myself, but I don't see what it wouldn't work. Or maybe I should say that if this does not work, it is very likely that there is a bug I need to fix. :) I also replied to your SO question, which is related to this problem. |
Beta Was this translation helpful? Give feedback.
-
Thank you Miguel for your reply. Let me know if you'd like to move this discussion on the intended location rather than here. I followed your suggestion with this code:
The output stops at "starting wait for clientS", which makes me think the first wait() call blocks the thread. Should I start the async method in a different way rather than through the run_until_complete() call? I will try this afternoon to change the async method to only start one client, so that I have to call it twice. Perhaps wait() only stops the execution of a single method call and having the same call scheduled twice would allow asyncio to keep the two clients in parallel? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Apologies if the question is not stricly related to Flask-SocketIO: this page redirects here.
I am effectively trying to handle two (or more) socketio.AsyncClient objects within the same asyncio loop.
So far I have been unsuccessful because it seems that each client needs a
asyncClient.wait()
line or awhile(True): await asyncClient.sleep(0)
codeblock afterasyncClient.connect()
to keep the connection up and running. But both options effectively block the thread and the code to instantiate and run the next AsyncClient is never reached.So far it seems to me I can only run multiple clients using multiple threads and therefore multiple asyncio loops. Is this correct or is there a way for multiple AsyncClients to interleave their activities within the same asyncio loop?
Alternatively, couldn't the AsyncClient instance keep the connection open until it is garbage-collected instead of closing it immediately after the connect() statement if there are no
wait()
orsleep()
statements following it?I posted this question also on StackOverflow: it is worded differently but it has some code and is effectively aiming at the same goal. Another question (not by me) seems to be heading in the same general direction.
Beta Was this translation helpful? Give feedback.
All reactions