diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 286132be..57a6b7b9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -22,6 +22,9 @@ Bug Fixes * Pass WriteType instance to RetryPolicy.on_write_timeout() instead of the string name of the write type. This caused write timeout errors to always be rethrown instead of retrying. (github #123) +* Avoid submitting tasks to the ThreadPoolExecutor after shutdown. With + retries enabled, this could cause Cluster.shutdown() to hang under + some circumstances. Other ^^^^^ diff --git a/cassandra/cluster.py b/cassandra/cluster.py index 95ed67e2..a9b3417d 100644 --- a/cassandra/cluster.py +++ b/cassandra/cluster.py @@ -130,6 +130,8 @@ def run_in_executor(f): @wraps(f) def new_f(self, *args, **kwargs): + if self.is_shutdown: + return try: future = self.executor.submit(f, self, *args, **kwargs) future.add_done_callback(_future_completed) @@ -1366,7 +1368,8 @@ class Session(object): def submit(self, fn, *args, **kwargs): """ Internal """ - return self.cluster.executor.submit(fn, *args, **kwargs) + if not self.is_shutdown: + return self.cluster.executor.submit(fn, *args, **kwargs) def get_pool_state(self): return dict((host, pool.get_state()) for host, pool in self._pools.items())