Skip to content

Commit 2ee077e

Browse files
committed
Merged PYTHON-752
2 parents bb501dd + 4fa0143 commit 2ee077e

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Bug Fixes
1414
* Error at cleanup when closing the asyncore connections (PYTHON-829)
1515
* Fix sites where `sessions` can change during iteration (PYTHON-793)
1616
* cqlengine: allow min_length=0 for Ascii and Text column types (PYTHON-735)
17+
* Rare exception when "sys.exit(0)" after query timeouts (PYTHON-752)
1718

1819
3.11.0
1920
======

cassandra/io/libevreactor.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(self):
6363
self._started = False
6464
self._shutdown = False
6565
self._lock = Lock()
66+
self._lock_thread = Lock()
6667

6768
self._thread = None
6869

@@ -94,9 +95,11 @@ def maybe_start(self):
9495
should_start = True
9596

9697
if should_start:
97-
self._thread = Thread(target=self._run_loop, name="event_loop")
98-
self._thread.daemon = True
99-
self._thread.start()
98+
with self._lock_thread:
99+
if not self._shutdown:
100+
self._thread = Thread(target=self._run_loop, name="event_loop")
101+
self._thread.daemon = True
102+
self._thread.start()
100103

101104
self._notifier.send()
102105

@@ -126,8 +129,11 @@ def _cleanup(self):
126129
watcher.stop()
127130

128131
self.notify() # wake the timer watcher
129-
log.debug("Waiting for event loop thread to join...")
130-
self._thread.join(timeout=1.0)
132+
133+
# PYTHON-752 Thread might have just been created and not started
134+
with self._lock_thread:
135+
self._thread.join(timeout=1.0)
136+
131137
if self._thread.is_alive():
132138
log.warning(
133139
"Event loop thread could not be joined, so shutdown may not be clean. "

0 commit comments

Comments
 (0)