Skip to content

Commit d80fa56

Browse files
committed
use getattr to check for close method in IOLoop.close
instead of catching AttributeError directly
1 parent a4279d2 commit d80fa56

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tornado/ioloop.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,10 @@ def close(self, all_fds=False):
505505
if all_fds:
506506
for fd in self._handlers.keys():
507507
try:
508-
try:
509-
fd.close()
510-
except AttributeError:
508+
close_method = getattr(fd, 'close', None)
509+
if close_method is not None:
510+
close_method()
511+
else:
511512
os.close(fd)
512513
except Exception:
513514
gen_log.debug("error closing fd %s", fd, exc_info=True)

0 commit comments

Comments
 (0)