简体   繁体   English

MessageLoop(bot, handle).run_forever() 在 Pycharm 中不起作用

[英]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.我在 cmd 和 Pycharm 中都尝试了以下代码。它对 cmd 运行良好,但结果证明代码在 Pycharm 中运行不佳。我无法获得任何更新,过程刚刚完成。 Can I know how to solve this?我能知道如何解决这个问题吗? PS : It worked in Pycharm when I change run_as_thread to run_forever() PS:当我将 run_as_thread 更改为 run_forever() 时,它在 Pycharm 中有效

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.您必须在此之后添加一个 While 循环,这将使您的程序阻塞。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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