Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cassandra/io/libevreactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def _cleanup(self):
if not self._thread:
return

# Stop the prepare watcher first to prevent race conditions
if self._preparer:
self._preparer.stop()

for conn in self._live_conns | self._new_conns | self._closed_conns:
conn.close()
for watcher in (conn._write_watcher, conn._read_watcher):
Expand All @@ -125,8 +129,9 @@ def _cleanup(self):
self.notify() # wake the timer watcher

# PYTHON-752 Thread might have just been created and not started
# Use longer timeout to allow proper cleanup
with self._lock_thread:
self._thread.join(timeout=1.0)
self._thread.join(timeout=5.0)

if self._thread.is_alive():
log.warning(
Expand Down
4 changes: 4 additions & 0 deletions cassandra/io/libevwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ static void prepare_callback(struct ev_loop *loop, ev_prepare *watcher, int reve
PyObject *result = NULL;
PyGILState_STATE gstate;

if (!self || !self->callback) {
return; // Skip callback if object is being destroyed
}

gstate = PyGILState_Ensure();
result = PyObject_CallFunction(self->callback, "O", self);
if (!result) {
Expand Down
Loading