When use_poll is True, test_handle_close in test_asyncore.py invokes twice the handle_close() method. The attached patch: modifies test_handle_close so that it fails when handle_close() is called more than once includes a fix that makes readwrite() behave like poll(): check that the dispatcher instance is still in the socket map, before calling the handle_xxx methods
To me the patched code in readwrite seems cut and paste. Could it be written something like this? have_fileno = not map or obj._fileno in map if have_fileno and flags & select.POLLIN: obj.handle_read_event() if have_fileno and flags & select.POLLOUT: obj.handle_write_event() if have_fileno and flags & select.POLLPRI: obj.handle_expt_event() if (have_fileno and flags & (select.POLLHUP | select.POLLERR