Search code examples
pythonsocketstornado

How do I close all sockets opened by Tornado?


Tornado has an open socket, and I can't seem to get it closed.

I was really surprised as I've turned my computer on and off since the last time I ran this server a week ago, and terminal is not running. All in all, I thought this server was off for the past week.

The things I've tried so far are the solution to this similar question: python websocket with tornado. Socket aren't closed, which did nothing.

And I've tried using IOLoop.close(all_fds=True) PyDoc for this function, which returned the error below.

>>> tornado.ioloop.IOLoop.close(all_fds=True)

Traceback (most recent call last):

File "", line 1, in

TypeError: unbound method close() must be called with IOLoop instance as first argument (got nothing instead)

How do I close all sockets so I can start up again from a clean slate?


Solution

  • Interesting.

    Firstly, you should call close() method for tornado.ioloop.IOLoop object, not for class object. You can get current tornado.ioloop.IOLoop object using the method tornado.ioloop.IOLoop.current().

    Example:

    my_ioloop = tornado.ioloop.IOLoop.current()
    my_ioloop.close(all_fds=True)
    

    Further reading: