如何将asyncore与Python3中的多处理IPC模块一起使用?

如何将asyncore与Python3中的多处理IPC模块一起使用?,python,sockets,event-handling,multiprocessing,asyncore,Python,Sockets,Event Handling,Multiprocessing,Asyncore,我试图利用多处理模块的客户机/服务器体系结构来促进Python脚本之间的通信。我希望能够使用asyncore实现一个独立于主事件循环的连接侦听器。我该怎么做 虽然没有关于如何执行此操作的外部文档,但我已尝试使用多处理中的侦听器套接字构建一个基本的asyncore.dispatcher: import asyncore import socket from multiprocessing.connection import Listener, Client class ConnectionLis

我试图利用
多处理
模块的客户机/服务器体系结构来促进Python脚本之间的通信。我希望能够使用
asyncore
实现一个独立于主事件循环的连接侦听器。我该怎么做

虽然没有关于如何执行此操作的外部文档,但我已尝试使用多处理中的侦听器套接字构建一个基本的
asyncore.dispatcher

import asyncore
import socket
from multiprocessing.connection import Listener, Client

class ConnectionListener(asyncore.dispatcher):
    def __init__(self, ln):
        asyncore.dispatcher.__init__(self)
        self.set_socket(ln._listener._socket)
    def handle_accepted(self, sock, addr):
        print("Accepted a client!")

if __name__ == "__main__":
    address = ('localhost', 19378)
    try:
        ln = Listener(address)
        x = ConnectionListener(ln)
        while True:
            asyncore.loop()
    except socket.error:
        c = Client(address)
        print("Client is trying to connect")

当服务器执行循环时,它从不触发
handle\u accepted

我认为您正在寻找的方法是handle\u accept,而不是handle\u accept