When a file object is used instead of a numeric file descriptor, the object should be closed (by IOLoop.close(all_fds=True), not just the fd.
(self)
| 255 | self.io_loop.remove_timeout(handle) |
| 256 | |
| 257 | def test_close_file_object(self): |
| 258 | """When a file object is used instead of a numeric file descriptor, |
| 259 | the object should be closed (by IOLoop.close(all_fds=True), |
| 260 | not just the fd. |
| 261 | """ |
| 262 | # Use a socket since they are supported by IOLoop on all platforms. |
| 263 | # Unfortunately, sockets don't support the .closed attribute for |
| 264 | # inspecting their close status, so we must use a wrapper. |
| 265 | class SocketWrapper(object): |
| 266 | def __init__(self, sockobj): |
| 267 | self.sockobj = sockobj |
| 268 | self.closed = False |
| 269 | |
| 270 | def fileno(self): |
| 271 | return self.sockobj.fileno() |
| 272 | |
| 273 | def close(self): |
| 274 | self.closed = True |
| 275 | self.sockobj.close() |
| 276 | |
| 277 | sockobj, port = bind_unused_port() |
| 278 | socket_wrapper = SocketWrapper(sockobj) |
| 279 | io_loop = IOLoop() |
| 280 | io_loop.add_handler(socket_wrapper, lambda fd, events: None, IOLoop.READ) |
| 281 | io_loop.close(all_fds=True) |
| 282 | self.assertTrue(socket_wrapper.closed) |
| 283 | |
| 284 | def test_handler_callback_file_object(self): |
| 285 | """The handler callback receives the same fd object it passed in.""" |
nothing calls this directly
no test coverage detected