ThriftConnect.py 876 Bytes
# coding=utf-8
#author:        4N
#createtime:    2021/9/8
#email:         nheweijun@sina.com

from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from app.modules.service.image.ImageDataService import ImageDataService

class ThriftConnect:
    '''
    thrift连接类
    '''

    client = None
    transport = None

    def __init__(self,data_server):
        host = data_server.split(":")[0]
        port = int(data_server.split(":")[1])
        self.transport: TSocket = TSocket.TSocket(host, port)
        self.transport = TTransport.TBufferedTransport(self.transport)
        protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.client = ImageDataService.Client(protocol)
        self.transport.open()

    def close(self):
        self.transport.close()