使用gunicorn

时间:2018-10-15 19:55:30

标签: python gunicorn thrift

我正在尝试使用Gunicorn建立一个节俭的python服务器。但是,我无法使客户端与服务器一起使用。我在这篇文章中添加了相关的代码片段。请让我知道我在这里想念什么。

我一直遇到的错误是

  

thrift-test / client.py”,第17行       响应= client.ping()     ping中的文件“ build / bdist.macosx-10.11-x86_64 / egg / contract / TestService.py”,第94行     在recv_ping中的第105行的文件“ build / bdist.macosx-10.11-x86_64 / egg / contract / TestService.py”     在第32行中输入文件“ build / bdist.macosx-10.11-x86_64 / egg / thrift / protocol / TProtocolDecorator.py”     _wrap中的文件“ build / bdist.macosx-10.11-x86_64 / egg / thrift / protocol / TProtocolDecorator.py”,第39行     在readMessageBegin中的第310行中,文件“ build / bdist.macosx-10.11-x86_64 / egg / thrift / protocol / TCompactProtocol.py”     __readUByte中的第289行的文件“ build / bdist.macosx-10.11-x86_64 / egg / thrift / protocol / TCompactProtocol.py”     文件“ build / bdist.macosx-10.11-x86_64 / egg / thrift / transport / TTransport.py”,第58行,在readAll中     读取文件“ build / bdist.macosx-10.11-x86_64 / egg / thrift / transport / THttpClient.py”,第97行   AttributeError:'NoneType'对象没有属性'read'

我使用以下命令运行gunicorn服务器:

  

gunicorn_thrift -k thrift_sync -b 127.0.0.1:9999 server:app --access-logfile'-'--error-logfile'-'--log-level'debug'--thrift-protocol-factory节俭。 protocol.TCompactProtocol:TCompactProtocolFactory

客户端代码为:

from thrift.transport import THttpClient
from thrift.protocol import TCompactProtocol
from thrift.protocol import TMultiplexedProtocol
from contract import TestService
from thrift.protocol import TBinaryProtocol

import logging
logging.basicConfig(level=logging.INFO)


transport = THttpClient.THttpClient('http://localhost:9999')
protocol=TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
p = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "testservice")
client = TestService.Client(p)
transport.open()
response = client.ping()
print response
transport.close()

这是Thrift Server.py的实现方式:

#! /usr/bin/env python
# tests/app.py
# -*- coding: utf-8 -*-


import logging
from thrift import TMultiplexedProcessor
from contract import TestService

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger('actions')

class TestServiceDispatcher(TestService.Iface):
    def test(self, request):
      pass

    def ping(self):
       log.info("accessing ping method")
       return "service ready"

def create_app():
   log.info("starting up the app")
   handler = TestServiceDispatcher()
   coretext_processor = TestService.Processor(handler)
   processor = TMultiplexedProcessor.TMultiplexedProcessor()
   processor.registerProcessor("testservice", coretext_processor)
   return processor

app = create_app()

节俭合同:

/**
* Exception is thrown when request has invalid input. message contains 
details regarding invalid input.
*/
exception InvalidInputException {
  10: required string message;
}


/**
 * Definition for the action service
 */
 service TestService {

   /**
    * predict method takes the vector as input and spits out the 
      predicted output
   **/
 string test(
    1: string request
 ) throws (
    1: InvalidInputException iie
 );

 /**
 * health check
 **/
 string ping()
 }

0 个答案:

没有答案