Commit 1ccc4478 authored by Kirill Smelkov's avatar Kirill Smelkov

X Use `with gil` + regular py code instead of...

X Use `with gil` + regular py code instead of PyGILState_Ensure/PyGILState_Release/PyRun_SimpleString
parent c3968d72
......@@ -29,7 +29,7 @@ from posix.unistd cimport write, sleep
from posix.types cimport off_t
from cpython.exc cimport PyErr_SetFromErrno
from cpython.pystate cimport PyGILState_Ensure, PyGILState_Release, PyGILState_STATE
#from cpython.pystate cimport PyGILState_Ensure, PyGILState_Release, PyGILState_STATE
# XXX -> cpython.lifecycle? .run ?
cdef extern from "Python.h":
......@@ -73,26 +73,27 @@ def install_sigbus_trap():
if err:
PyErr_SetFromErrno(OSError)
cdef void on_sigbus(int sig, siginfo_t *si, void *_uc):
cdef void on_sigbus(int sig, siginfo_t *si, void *_uc) nogil:
# - wait a bit to give time for other threads to complete their exception dumps
# (e.g. getting "Transport endpoint is not connected" after wcfs.go dying)
# - dump py-level traceback and abort.
# TODO turn SIGBUS into python-level exception? (see sigpanic in Go how to do).
writeerr("\nC: SIGBUS received; giving time to other threads " +
writeerr("\nC: SIGBUS received; giving time to other threads "
"to dump their exceptions (if any) ...\n")
cdef PyGILState_STATE gstate = PyGILState_Ensure()
PyGILState_Release(gstate)
with gil:
pass
sleep(1)
writeerr("\nC: SIGBUS'ed thread traceback:\n")
PyGILState_Ensure()
PyRun_SimpleString("import traceback; traceback.print_stack()")
with gil:
import traceback
traceback.print_stack()
writeerr("-> SIGBUS\n");
abort()
# writeerr writes msg to stderr without depending on stdio buffering and locking.
cdef void writeerr(const char *msg):
cdef void writeerr(const char *msg) nogil:
cdef ssize_t n, left = strlen(msg)
while left > 0:
n = write(2, msg, left)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment