You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.
Hello, I recently switched to the async version, and I'm trying to replicate the behavior I had before, which is the following.
the bot must be able to do two different things:
Receive a msg and handle it, doing some stuff depending on the content
Send some msg when some data is collected (by sensors)
This is the code in the standard (not async version) I used to run:
importtelepotfromtelepot.loopimportMessageLoopfrommultiprocessing.connectionimportListener, Clientaddr= ('localhost', 4000)
listener=Listener(addr)
telegram_id="my ID"defhandle(msg):
# do some processing and maybe sending a msgbot=telepot.Bot(token)
MessageLoop(bot, handle).run_as_thread()
whileTrue:
conn=listener.accept()
data=conn.recv()
conn.close()
# some processing on databot.sendMessage(telegram_id, data)
I cannot replicate this behavior in the async version (I'm not very fond on async programming, actually)
I tried many thing, including the following.
frommultiprocessing.connectionimportListener, Clientimportasyncioimporttelepotimporttelepot.aioaddr= ('localhost', 4000)
listener=Listener(addr)
telegram_id="myid"asyncdefget_data():
print("Waiting for data")
conn=listener.accept()
data=conn.recv()
conn.close()
returndataasyncdefinternal_handle():
whileTrue:
data=awaitasyncio.run(get_data())
# process dataawaitbot.sendMessage(telegram_id, data)
asyncdefhandle(msg):
# same stuff as beforebot=telepot.aio.Bot("token")
loop=asyncio.get_event_loop()
loop.create_task(internal_handle())
loop.create_task(MessageLoop(bot, handle).run_forever())
loop.run_forever()
I thought this would run internale_handle() and the msg handler together, but it doesn't. Instead, it gets stuck waiting for data from the Listener.
Thank you for any suggestion!
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello, I recently switched to the async version, and I'm trying to replicate the behavior I had before, which is the following.
the bot must be able to do two different things:
This is the code in the standard (not async version) I used to run:
I cannot replicate this behavior in the async version (I'm not very fond on async programming, actually)
I tried many thing, including the following.
I thought this would run
internale_handle()
and the msg handler together, but it doesn't. Instead, it gets stuck waiting for data from the Listener.Thank you for any suggestion!
The text was updated successfully, but these errors were encountered: