Friday, 30 August 2019

ValueError: filedescriptor out of range in select() while using thrift?

I'm tring to provide a remote server by thrift, and below is my server-side trial:

from test_thrift.test_server.TestService import Iface,Processor
from thrift.Thrift import TType,TException
from thrift.Thrift import TProcessor
from thrift.transport import TSocket
from thrift.protocol import TBinaryProtocol
from thrift.server import TNonblockingServer


port = int(config["server"]["port"])
handler = SmbService()
processor = Processor(handler)
socket = TSocket.TServerSocket(port=port)
server = TNonblockingServer.TNonblockingServer(processor, socket)

server.setNumThreads(100)
server.serve()


At my client-side, for every request I will create a new connect and close it after got response from server.

from thrift.transport.TSocket import TTransportException
from thrift.Thrift import TException
from thrift.protocol import TBinaryProtocol, TCompactProtocol
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift import Thrift
from test_thrift.test_server import TestService


class SmbClient(object):
    def __init__(self):
        try:
            self.tsocket = TSocket.TSocket(settings.THRIFT_HOST, settings.THRIFT_PORT_PRODUCT)
            self.transportFactory = TTransport.TFramedTransportFactory()
            self.transport = self.transportFactory.getTransport(self.tsocket)
            self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
            self.client = ProductServer.Client(self.protocol)
            self.transport.open()
        except Thrift.TException as e:
            self.logger.info(e)



class BaseService(object):

    def __init__(self):
        self.commonLogger = logging.getLogger('ads')
        self.header = "header111"

    def search_ads_list(self, request, account_id):
        self.smbClient.client.getFBAdsByAccount(param1, param2)

    def __enter__(self):
        self.smbClient = SmbClient()
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.smbClient.transport.close()


ech request call is like this:

 with BaseService() as BaseSingleService:
            status, data, info = BaseSingleService.search_ads_list(
                request, account_id)


The actual amount of requests from client are not big enough , but after period of time. I got error like :

Traceback (most recent call last):
  File "/home/xxx/xxx/src/smb_thrift_server.py", line 2200, in <module>
    server.serve()
  File "/home/xxx/xxx/venv3/lib/python3.5/site-packages/thrift/server/TNonblockingServer.py", line 350, in serve
    self.handle()
  File "/home/xxx/xxxx/venv3/lib/python3.5/site-packages/thrift/server/TNonblockingServer.py", line 310, in handle
    rset, wset, xset = self._select()
  File "/home/luban/smb_thrift_server/venv3/lib/python3.5/site-packages/thrift/server/TNonblockingServer.py", line 302, in _select
    return select.select(readable, writable, readable)
ValueError: filedescriptor out of range in select()

Why error happended as I've closed the client connect each time after receiving the response?



from ValueError: filedescriptor out of range in select() while using thrift?

No comments:

Post a Comment