MessageLoop(bot, handle).run_forever() doesn't work in Pycharm

1k Views Asked by At

I tried the following code in both cmd and Pycharm.It worked well for the cmd but it turned out that the code did not work well in the Pycharm.I couldn't get any updates and the process just finished. Can I know how to solve this? PS : It worked in Pycharm when I change run_as_thread to run_forever()

import telepot

from pprint import pprint

from telepot.loop import MessageLoop

bot = telepot.Bot("999999999999999999")

def handle(msg):

    pprint(msg)


a =  MessageLoop(bot, handle).run_as_thread()
1

There are 1 best solutions below

0
On

You have to add a While loop after this which will keep your program blocking.

like -

MessageLoop(bot, handle).run_as_thread()
print ('Listening....')
while 1:
    sleep(10)

or make it run forever it will block automatically

MessageLoop(bot, handle).run_forever()