Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
客户端中的Python asyncore.loop_Python_Sockets_Asyncore - Fatal编程技术网

客户端中的Python asyncore.loop

客户端中的Python asyncore.loop,python,sockets,asyncore,Python,Sockets,Asyncore,我在谷歌上搜索了很多文章,但仍然没有重要的信息 我的问题是如何在客户端停止asyncore.loop() 我的代码如下 导入套接字,异步 class Client(asyncore.dispatcher): def __init__(self, host, port): self.buffer = '' asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET

我在谷歌上搜索了很多文章,但仍然没有重要的信息

我的问题是如何在客户端停止asyncore.loop()

我的代码如下 导入套接字,异步

class Client(asyncore.dispatcher):
    def __init__(self, host, port):
        self.buffer = ''
        asyncore.dispatcher.__init__(self)

        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect((host, port))

    def writable(self):
        return len(self.buffer) > 0

    def handle_connect(self):
        print "handle_connect"

    def handle_close(self):
        print "handle_close"
        self.close()

    def handle_write(self):
        print "handle_write"
        sent = self.send(self.buffer)
        self.buffer = self.buffer[sent:]
        print sent

    def command(self, data):
        self.buffer = data

    def close(self):
        self.close()


mysocket = Client("127.0.0.1", 8888)
mysocket.command("asfas\n")

asyncore.loop()

mysocket.close()

提前谢谢

为什么需要停止循环?您想在停止后完成一些操作吗?请参阅-我认为,这将对您有所帮助谢谢您的评论@Dmitry。我需要它,因为这是客户端,在运行命令之后,客户端脚本应该退出。您的第二条评论是针对服务器端的。