Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81faea2

Browse files
KowalskiThomasabsurdfarce
authored andcommitted
Prevent crash at exit
patch by Thomas Kowalski; reviewed by Bret McGuire and Brad Schoening reference: #1287
1 parent f685c2c commit 81faea2

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

cassandra/io/libevreactor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _loop_will_run(self, prepare):
225225

226226

227227
_global_loop = None
228-
atexit.register(partial(_cleanup, _global_loop))
228+
atexit.register(lambda: _cleanup(_global_loop))
229229

230230

231231
class LibevConnection(Connection):

cassandra/io/libevwrapper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ IO_dealloc(libevwrapper_IO *self) {
114114
};
115115

116116
static void io_callback(struct ev_loop *loop, ev_io *watcher, int revents) {
117+
if (!Py_IsInitialized()) {
118+
return;
119+
}
120+
117121
libevwrapper_IO *self = watcher->data;
118122
PyObject *result;
119123
PyGILState_STATE gstate = PyGILState_Ensure();
@@ -348,6 +352,10 @@ Prepare_dealloc(libevwrapper_Prepare *self) {
348352
}
349353

350354
static void prepare_callback(struct ev_loop *loop, ev_prepare *watcher, int revents) {
355+
if (!Py_IsInitialized()) {
356+
return;
357+
}
358+
351359
libevwrapper_Prepare *self = watcher->data;
352360
PyObject *result = NULL;
353361
PyGILState_STATE gstate;
@@ -466,6 +474,10 @@ Timer_dealloc(libevwrapper_Timer *self) {
466474
}
467475

468476
static void timer_callback(struct ev_loop *loop, ev_timer *watcher, int revents) {
477+
if (!Py_IsInitialized()) {
478+
return;
479+
}
480+
469481
libevwrapper_Timer *self = watcher->data;
470482

471483
PyObject *result = NULL;

0 commit comments

Comments
 (0)