Closed kokojiji01 closed 3 years ago
This problem is caused by bad internet or disconnections and it's caused by your msg = await ms.recv()
, where it will try to wait for that data, even if it can't ever find one, thus, blocking the execution of the whole code.
To solve the problem you should use the asyncio
function wait_for()
in place of your msg = await ms.recv()
As in: msg = await asyncio.wait_for(ms.recv(), SECONDS_TO_TIMEOUT)
Hello! I noticed that after around 42 seconds my application freezes
I can get rid of the error by removing the line await time.sleep(0.1) in my code. But in my actual trading bot there is some math that needs to be done and the sleep is command is replacing it.
Here's my code to illustrate the issue:
Expected behavior Expecting a continuous stream of messages. Instead stream freezes permanently after around 42 second.
Environment (please complete the following information):
Note Repost of https://github.com/sammchardy/python-binance/issues/862#issue-894140160 that was supposed to be fixed but wasn't. Switched the following line from the original post. await
asyncio.sleep(0.1)
totime.sleep(0.1)
I don't know if this makes a difference but in my real application the thread is busy doing math so it isn't something that can be awaited if have understood coroutines correctly.