timeout-decorator icon indicating copy to clipboard operation
timeout-decorator copied to clipboard

Using thread-safe version of timeout decorator in a serwer

Open wojciech-galan opened this issue 9 years ago • 1 comments

I've got a server using ThreadingMixIn:

class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
    pass

class RequestHandler(SocketServer.StreamRequestHandler):

    @timeout_decorator.timeout(seconds=5, use_signals=False)
    def handle(self):
        #do some time-consuming stuff

if __name__ == '__main__':
    server = ThreadingTCPServer((server_ip, server_port), RequestHandler)
    server.serve_forever()

When I run the server and a client sending requests to the server, I get the following error:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 599, in process_request_thread
    self.handle_error(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 596, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 652, in __init__
    self.handle()
  File "/usr/local/lib/python2.7/dist-packages/timeout_decorator/timeout_decorator.py", line 132, in __call__
    return self.value
  File "/usr/local/lib/python2.7/dist-packages/timeout_decorator/timeout_decorator.py", line 154, in value
    raise load
TypeError: handle() takes exactly 1 argument (0 given)

Is there something wrong with my code?

wojciech-galan avatar Sep 15 '16 14:09 wojciech-galan

You can try my Version, its using wrapt instead functools - it should behave correctly : https://github.com/bitranox/timeout-decorator Yours sincerely Robert

bitranox avatar Nov 09 '17 11:11 bitranox