]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
try close method to close FDs in IOLoop
authorMinRK <benjaminrk@gmail.com>
Mon, 15 Apr 2013 18:36:58 +0000 (11:36 -0700)
committerMinRK <benjaminrk@gmail.com>
Mon, 15 Apr 2013 18:36:58 +0000 (11:36 -0700)
If an object has a `close` method, use that first,
then fallback on `os.close`.

This is useful in subclasses that support polling things (zmq sockets, specifically)
that are not simple FDs (and Jython, I hear?).

tornado/ioloop.py

index efe90d4068388e367f863ec2ac21cce4eb8cb66e..66c38945849d2eeb3ed898e97e6f1ddcd0b7d721 100644 (file)
@@ -505,7 +505,10 @@ class PollIOLoop(IOLoop):
         if all_fds:
             for fd in self._handlers.keys():
                 try:
-                    os.close(fd)
+                    try:
+                        fd.close()
+                    except AttributeError:
+                        os.close(fd)
                 except Exception:
                     gen_log.debug("error closing fd %s", fd, exc_info=True)
         self._waker.close()