扭曲的irc python bot-缓冲消息
作者:互联网
“Why does it take a long time for data I send with transport.write to arrive at the other side of the connection?”
Twisted can only send data after you give up control of execution to the reactor. For example, if you have an infinite loop writing data to a transport, the data will never actually be sent since control will never leave your code and return to the reactor.”
我在扭曲的FAQ中找到了它,这正是我的问题.有没有一种方法可以解决此问题,以便我可以立即发送消息而不必等待循环结束?
解决方法:
不可以.您不能立即发送消息.控件必须返回事件循环.幸运的是,您真正要解决的问题(从对问题的评论中推断出),对您发送的消息进行速率限制并不需要做到这一点.相反,请停止在循环中使用time.sleep并开始使用reactor.callLater延迟执行代码.或使用IRC API的功能为您完成这些操作(lineRate您似乎已经发现了).
标签:irc,bots,twisted,python 来源: https://codeday.me/bug/20191101/1982331.html