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 Bug Fixes
--------- ---------
* is_idempotent flag is not propagated from PreparedStatement to BoundStatement (PYTHON-736) * is_idempotent flag is not propagated from PreparedStatement to BoundStatement (PYTHON-736)
* Fix asyncore hang on exit (PYTHON-767)
Other Other
----- -----

View File

@@ -240,6 +240,8 @@ class AsyncoreLoop(object):
self._timers.add_timer(timer) self._timers.add_timer(timer)
def _cleanup(self): def _cleanup(self):
global _dispatcher_map
self._shutdown = True self._shutdown = True
if not self._thread: if not self._thread:
return return
@@ -253,6 +255,12 @@ class AsyncoreLoop(object):
log.debug("Event loop thread was joined") 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): 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 #This happens when the connection is shutdown while waiting for the ReadyMessage
if not self.connected_event.is_set(): if not self.connected_event.is_set():
self.last_error = ConnectionShutdown("Connection to %s was closed" % self.host) self.last_error = ConnectionShutdown("Connection to %s was closed" % self.host)
# don't leave in-progress operations hanging # don't leave in-progress operations hanging
self.connected_event.set() self.connected_event.set()