python IRC 缓冲区未清除
我的 IRC 机器人有一个简单的缓冲系统,这样它就不会因为网络延迟等原因而错过一行。 我使用以下代码来启动处理从服务器接收到的信息的循环:
while 1: #Start the main loop
self.readbuffer += s.recv(1024).decode()
temp=self.readbuffer.split("\n")
self.readbuffer=temp.pop()
问题是缓冲区似乎永远不会清除,因此每当我想对数据执行某些操作时,它都会循环遍历所有内容。因此,如果我告诉机器人做某事,它也会做之前做过的所有事情。通过调试我已经确认缓冲区确实永远不会被清除。 那么...根据上面的代码(唯一修改缓冲区的代码)我的问题是什么? 感谢您的阅读。
I have a simply buffer system for my IRC bot so it never misses a line due to network lag and such.
I am using the following code to start the loop that processes information received from the server:
while 1: #Start the main loop
self.readbuffer += s.recv(1024).decode()
temp=self.readbuffer.split("\n")
self.readbuffer=temp.pop()
The problem is that it seems that the buffer never clears, so any time I want to do something with the data it loops through everything. So if I tell the bot to do something, it does everything it's done before as well. Through debugging I've confirmed that the buffer is indeed never clearing.
So... based on the code above (the only code that ever modifies the buffer) what is my problem?
Thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里尝试清除缓冲区?
self.readbuffer += s.recv(1024).decode()
向 readbuffer 添加更多数据。temp=self.readbuffer.split("\n")
将 readbuffer 转换为单行字符串列表self.readbuffer=temp.pop() 使 readbuffer 成为最后一行
如果 readbuffer 永远不会变小,那一定是因为您从未收到换行符。也许 IRC 使用
'\r'
或其他代码来指示新帖子?Where do you try to clear the buffer?
self.readbuffer += s.recv(1024).decode()
adds more data to readbuffer.temp=self.readbuffer.split("\n")
turns readbuffer into a list of one-line stringsself.readbuffer=temp.pop()
makes readbuffer the last lineIf readbuffer never gets smaller, it must be because you never receive a newline character. Perhaps IRC uses
'\r'
or some other code to indicate a new post?