The tests test.test_asyncore.TestAPI_UseIPv4Select.test_handle_close_after_conn_broken test.test_asyncore.TestAPI_UseIPv6Select.test_handle_close_after_conn_broken can fail randomly (see python issue #29151 [0]). Sleeping for a short moment before writing bytes to the socket seems to circumvent this problem. [0] https://bugs.python.org/issue29151 diff -ur a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -632,6 +632,7 @@ class TestClient(BaseClient): def handle_write(self): + time.sleep(0.01) # workaround for issue #11265 self.send(data) def handle_close(self):