我有一个简单的问题。
例如,当我使用示例代码创建 python TCPServer 时:
import sys, SocketServer, os
from multiprocessing import Pool, Queue
class MyTCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
# self.request is the TCP socket connected to the client
self.data = self.request.recv(1024).strip()
print "{} wrote:".format(self.client_address[0])
print self.data
# just send back the same data, but upper-cased
self.request.sendall(self.data.upper())
if __name__ == '__main__':
pool = Pool(processes=2)
HOST, PORT = "localhost", 9999
server = SocketServer.TCPServer((HOST,PORT), MyTCPHandler )
server.serve_forever()
我的问题是:如何将对象池传递给 MyTCPHandler 类的函数句柄?
谢谢