Merge pull request #779 from datastax/python-767

Ensure asyncore dispatchers are closed on shutdown
This commit is contained in:
Alan Boudreault
2017-06-07 07:50:37 -04:00
committed by GitHub
2 changed files with 10 additions and 1 deletions

View File

@@ -4,6 +4,7 @@
Bug Fixes
---------
* is_idempotent flag is not propagated from PreparedStatement to BoundStatement (PYTHON-736)
* Fix asyncore hang on exit (PYTHON-767)
Other
-----

View File

@@ -240,6 +240,8 @@ class AsyncoreLoop(object):
self._timers.add_timer(timer)
def _cleanup(self):
global _dispatcher_map
self._shutdown = True
if not self._thread:
return
@@ -253,6 +255,12 @@ class AsyncoreLoop(object):
log.debug("Event loop thread was joined")
# Ensure all connections are closed and in-flight requests cancelled
for conn in tuple(_dispatcher_map.values()):
conn.close()
log.debug("Dispatchers were closed")
class AsyncoreConnection(Connection, asyncore.dispatcher):
"""
@@ -326,7 +334,7 @@ class AsyncoreConnection(Connection, asyncore.dispatcher):
#This happens when the connection is shutdown while waiting for the ReadyMessage
if not self.connected_event.is_set():
self.last_error = ConnectionShutdown("Connection to %s was closed" % self.host)
# don't leave in-progress operations hanging
self.connected_event.set()