This is an automated email from the ASF dual-hosted git repository.

absurdfarce pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-python-driver.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 81faea21 Prevent crash at exit
81faea21 is described below

commit 81faea210aef6b32a6286dbe4abd220fe417e8c0
Author: Thomas Kowalski <[email protected]>
AuthorDate: Fri Apr 10 16:08:01 2026 +0200

    Prevent crash at exit
    
    patch by Thomas Kowalski; reviewed by Bret McGuire and Brad Schoening
    reference: https://github.com/apache/cassandra-python-driver/pull/1287
---
 cassandra/io/libevreactor.py |  2 +-
 cassandra/io/libevwrapper.c  | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/cassandra/io/libevreactor.py b/cassandra/io/libevreactor.py
index 275f79c3..76a53b9b 100644
--- a/cassandra/io/libevreactor.py
+++ b/cassandra/io/libevreactor.py
@@ -225,7 +225,7 @@ class LibevLoop(object):
 
 
 _global_loop = None
-atexit.register(partial(_cleanup, _global_loop))
+atexit.register(lambda: _cleanup(_global_loop))
 
 
 class LibevConnection(Connection):
diff --git a/cassandra/io/libevwrapper.c b/cassandra/io/libevwrapper.c
index 85ed5519..84d3d16b 100644
--- a/cassandra/io/libevwrapper.c
+++ b/cassandra/io/libevwrapper.c
@@ -114,6 +114,10 @@ IO_dealloc(libevwrapper_IO *self) {
 };
 
 static void io_callback(struct ev_loop *loop, ev_io *watcher, int revents) {
+    if (!Py_IsInitialized()) {
+        return;
+    }
+
     libevwrapper_IO *self = watcher->data;
     PyObject *result;
     PyGILState_STATE gstate = PyGILState_Ensure();
@@ -348,6 +352,10 @@ Prepare_dealloc(libevwrapper_Prepare *self) {
 }
 
 static void prepare_callback(struct ev_loop *loop, ev_prepare *watcher, int 
revents) {
+    if (!Py_IsInitialized()) {
+        return;
+    }
+
     libevwrapper_Prepare *self = watcher->data;
     PyObject *result = NULL;
     PyGILState_STATE gstate;
@@ -466,6 +474,10 @@ Timer_dealloc(libevwrapper_Timer *self) {
 }
 
 static void timer_callback(struct ev_loop *loop, ev_timer *watcher, int 
revents) {
+    if (!Py_IsInitialized()) {
+        return;
+    }
+
     libevwrapper_Timer *self = watcher->data;
 
     PyObject *result = NULL;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to