“我犯了个错误”异常。属性错误:MyServerFactory实例没有“isLeaf”属性
我的代码如下,它是为单客户端连接工作,然后我尝试为多个客户端进行更改,但现在失败了。你知道吗
#!/usr/bin/python
import sys
###### for autogeneration please do not write new imports above this line #########
from twisted.web import xmlrpc, server
import twisted
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
PORT = 2222
SERVER_INFO = 'testing concurrency'
class TwiestedServer(xmlrpc.XMLRPC, Protocol):
"""
An example of using you own policy to fetch the handler
"""
"""
=======================================================
Function name : __init__
Purpose : Initialize libraries and add functions
Inputs : self
args
kwargs
Outputs : none
=======================================================
"""
def __init__(self,factory):
xmlrpc.XMLRPC.__init__(self)
# init libraries
self._procedureToCallable = {}
self.factory = factory
# add functions
self._procedureToCallable = {
'get_server_info': self.get_server_info,
}
"""
=======================================================
Function name : __dir__
Purpose :
Inputs : self
Outputs : none
=======================================================
"""
def __dir__(self):
dir_list1 = [k for k in self.__dict__]
dir_list2 = [k for k in self._procedureToCallable]
dir_list = dir_list1 + dir_list2
return dir_list
def fio(self,x):
if x == 1 or x == 2:
return 1
else:
return self.fio(x-1) + self.fio (x-2)
"""
=======================================================
Function name : get_server_info
Purpose : Get information about server
Inputs : self
Outputs : none
=======================================================
"""
def get_server_info(self,x):
return self.fio(x)
#return SERVER_INFO
"""
=======================================================
Function name : lookupProcedure
Purpose : Check if proceedure that has to be called
is available in class
Inputs : self
procedurePath
Outputs : none
=======================================================
"""
def lookupProcedure(self, procedurePath):
try:
return self._procedureToCallable[procedurePath]
except KeyError, e:
raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
"procedure %s not found" % procedurePath)
"""
=======================================================
Function name : direct_server_method
Purpose : Display that one is present on server
library
Inputs : self
Outputs : none
=======================================================
"""
def direct_server_method(self):
return "I am direct on server library"
"""
=======================================================
Function name : listProcedures
Purpose :
Inputs : self
Outputs : none
=======================================================
"""
def listProcedures(self):
"""
Since we override lookupProcedure, its suggested to override
listProcedures too.
"""
return self.__dir__()
"""
=======================================================
Function name : _ebRender
Purpose : To throw error
Inputs : self
failure
Outputs : Failure value
=======================================================
"""
def _ebRender(self, failure):
#if isinstance(failure.value, xmlrpc.Fault):
# return failure.value
return xmlrpc.Fault(str(failure), "error")
class MyServerFactory(Factory):
def buildProtocol(self, addr):
return TwiestedServer(self)
if __name__ == '__main__':
try:
from twisted.internet import reactor, protocol
r = MyServerFactory()
reactor.listenTCP(PORT, server.Site(r))
reactor.run()
except twisted.internet.error.CannotListenError as e:
sys.stderr.write(str(e))
sys.exit(98)
我们已经使用fio函数来测试客户端的并发性,因为fio(40)大约需要2-3分钟,同时服务器应该解析fio(3)。你知道吗
提前谢谢。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐