2011-12-05 85 views
4

在下面的代碼片段中,我試圖在python中創建一個非阻塞節儉服務器。Python中的非阻塞節儉服務器

# set handler to our implementation 
    handler = ServiceHandler() 

    processor = MyService.Processor(handler) 
    transport = TSocket.TServerSocket(port=port) 
    tfactory = TTransport.TFramedTransport(transport) 
    pfactory = TBinaryProtocol.TBinaryProtocolFactory() 

    # set server 
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) 

    print 'Python Server has started listening on port ' + str(port) 
    print '################################################' 
    server.serve() 

當python客戶端嘗試連接具有上述代碼段的服務器時,出現以下錯誤。你能告訴我什麼可能導致這個錯誤?可能我錯過了一些東西。

Exception in thread Thread-1: 
    Traceback (most recent call last): 
    File "/usr/lib64/python2.6/threading.py", line 522, in __bootstrap_inner 
    self.run() 
    File "/usr/lib64/python2.6/threading.py", line 477, in run 
    self.__target(*self.__args, **self.__kwargs) 
    File "/usr/local/lib64/python2.6/site-packages/thrift/server/TServer.py", line 114, in handle 
    itrans = self.inputTransportFactory.getTransport(client) 
    AttributeError: TFramedTransport instance has no attribute 'getTransport' 
+0

以上錯誤狀態信息是在服務器端的FYI上發出的。 –

回答

8

我發現了一些working Thrift code,它看起來像你的tfactory需要一個TBufferedTransportFactory而不是TBufferedTransport實例。

tfactory = TTransport.TBufferedTransportFactory() 
+0

的確是這個問題非常感謝。 –

+0

由於錯誤投票,現在無法編輯!抱歉! – Checksum