Skip to content

Commit 8e67b91

Browse files
authored
Merge pull request apache#779 from datastax/python-767
Ensure asyncore dispatchers are closed on shutdown
2 parents d6b211b + 78691a7 commit 8e67b91

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Bug Fixes
55
---------
66
* is_idempotent flag is not propagated from PreparedStatement to BoundStatement (PYTHON-736)
7+
* Fix asyncore hang on exit (PYTHON-767)
78

89
Other
910
-----

cassandra/io/asyncorereactor.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ def add_timer(self, timer):
240240
self._timers.add_timer(timer)
241241

242242
def _cleanup(self):
243+
global _dispatcher_map
244+
243245
self._shutdown = True
244246
if not self._thread:
245247
return
@@ -253,6 +255,12 @@ def _cleanup(self):
253255

254256
log.debug("Event loop thread was joined")
255257

258+
# Ensure all connections are closed and in-flight requests cancelled
259+
for conn in tuple(_dispatcher_map.values()):
260+
conn.close()
261+
262+
log.debug("Dispatchers were closed")
263+
256264

257265
class AsyncoreConnection(Connection, asyncore.dispatcher):
258266
"""
@@ -326,7 +334,7 @@ def close(self):
326334
#This happens when the connection is shutdown while waiting for the ReadyMessage
327335
if not self.connected_event.is_set():
328336
self.last_error = ConnectionShutdown("Connection to %s was closed" % self.host)
329-
337+
330338
# don't leave in-progress operations hanging
331339
self.connected_event.set()
332340

0 commit comments

Comments
 (0)