1

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?

Community
  • 1
  • 1
Seph Reed
  • 8,797
  • 11
  • 60
  • 125

2 Answers2

2

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:

Viach Kakovskyi
  • 1,487
  • 1
  • 14
  • 21
0

In my case, the issue was not with Tornado specifically, but with a process it started which continued even after it lost track of it.

When I restarted my computer, OSX kept track of the process, but Tornado did not. The solution was to find open ports and close the one Tornado was using.

The answer comes from here originally: https://stackoverflow.com/a/17703016/4808079

//first, check the port which your code opens.
$ sudo lsof -i :8528
COMMAND   PID USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
Python  29748 root    4u  IPv6 0xe782a7ce5603265      0t0  TCP *:8528 (LISTEN)
Python  29748 root    5u  IPv4 0xe782a7ce4aec61d      0t0  TCP *:8528 (LISTEN)

//then kill the process, using the PID
$ sudo kill 29748
Seph Reed
  • 8,797
  • 11
  • 60
  • 125