简体   繁体   中英

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

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()

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM