summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-03-26 23:13:32 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-03-26 23:13:32 +0200
commit291cf5046f1497c49b0266d0d818882a2b96d5d4 (patch)
treeadca60eb2612792e5616cc14be1557410efee226
parentbf068ebf9e86f527474e30bdaf4a74503f11d608 (diff)
downloaddiscordbot-1.6.0.tar.gz
discordbot-1.6.0.zip
fix timeout occuring too early, kill websocket when it's not needed anymore1.6.0
-rw-r--r--main.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/main.py b/main.py
index 0b81fa8..a80dc92 100644
--- a/main.py
+++ b/main.py
@@ -154,12 +154,13 @@ async def vainsocial(name: str):
io = SocketIO("localhost", 8080, LoggingNamespace)
io.on(name, update_available)
- asyncio.ensure_future(request_update())
- asyncio.ensure_future(
+ socket_waiter = asyncio.ensure_future(
bot.loop.run_in_executor(threadpool, io.wait, TIMEOUT))
+ asyncio.ensure_future(request_update())
has_embed = False
- for _ in range(TIMEOUT):
+ poll_frequency = 5 # Hz
+ for _ in range(TIMEOUT*poll_frequency):
if vainsocial.do_update:
logging.info("%s: updating bot response", name)
vainsocial.do_update = False
@@ -170,7 +171,9 @@ async def vainsocial(name: str):
embed=emb(data))
if not vainsocial.wait_for_update:
break
- await asyncio.sleep(0.1)
+ await asyncio.sleep(1.0/poll_frequency)
+
+ socket_waiter.cancel() # stop listening on websocket
if has_embed:
await bot.edit_message(bot_response, "Up to date.")