简体   繁体   中英

Non-blocking Thrift Server in Python

In below code snippet, I am trying to make a non-blocking thrift server in 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()

I am getting the following error when the python client attempts to connect the server having tyhe above code snippet. Could you please tell me what can be causing this error? Probably I am missing something.

    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'

我找到了一些有效的Thrift代码 ,看起来你的tfactory需要是TBufferedTransportFactory而不是TBufferedTransport实例。

tfactory = TTransport.TBufferedTransportFactory()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM