Skip to content

Commit 4fa0143

Browse files
committed
Don't join the thread if it hasn't been started
1 parent 496391e commit 4fa0143

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Bug Fixes
1111
* Use of DCAwareRoundRobinPolicy raises NoHostAvailable exception (PYTHON-781)
1212
* Not create two sessions by default in CQLEngine (PYTHON-814)
1313
* Bug when subclassing AyncoreConnection (PYTHON-827)
14+
* Rare exception when "sys.exit(0)" after query timeouts (PYTHON-752)
1415

1516
3.11.0
1617
======

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)