我有一个实例化xmlrpclib.ServerProxy
一次的应用程序,然后将其传递给多个线程(Web应用程序请求),这些线程同时执行XML/RPC调用.这适用于python 2.6.使用python 2.7,我们在多线程环境中遇到很多错误(ResponseNotReady
,CannotSendRequest
).
# This code works well in python 2.6, and breaks in python 2.7. import xmlrpclib import thread proxy = xmlrpclib.ServerProxy("http://localhost:5000/") def fetch_users(): print proxy.getUsers() for _ in range(10): thread.start_new_thread(fetch_users, ()) while(1): pass
这里有什么问题,是否有一种重新使用ServerProxy对象的线程安全方法?