2

我在 cmd 和 Pycharm 中都尝试了以下代码。它在 cmd 中运行良好,但结果证明该代码在 Pycharm 中运行不佳。我无法获得任何更新,并且该过程刚刚完成。我能知道如何解决这个问题吗?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()
4

1 回答 1

2

您必须在此之后添加一个 While 循环,这将使您的程序保持阻塞。

喜欢 -

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

或者让它永远运行它会自动阻塞

MessageLoop(bot, handle).run_forever()
于 2020-01-12T12:00:43.167 回答