• Kirill Smelkov's avatar
    Nogil signals · e18adbab
    Kirill Smelkov authored
    Provide os/signal package that can be used to setup signal delivery to nogil
    channels. This way for user code signal handling becomes regular handling of a
    signalling channel instead of being something special or limited to only-main
    python thread. The rationale for why we need it is explained below:
    
    There are several problems with regular python's stdlib signal module:
    
    1. Python2 does not call signal handler from under blocked lock.acquire.
       This means that if the main thread is blocked waiting on a semaphore,
       signal delivery will be delayed indefinitely, similarly to e.g. problem
       described in nxdtest!14 (comment 147527)
       where raising KeyboardInterrupt is delayed after SIGINT for many,
       potentially unbounded, seconds until ~semaphore wait finishes.
    
       Note that Python3 does not have this problem wrt stdlib locks and
       semaphores, but read below for the next point.
    
    2. all pygolang communication operations (channels send/recv, sync.Mutex,
       sync.RWMutex, sync.Sema, sync.WaitGroup, sync.WorkGroup, ...) run with
       GIL released, but if blocked do not handle EINTR and do not schedule
       python signal handler to run (on main thread).
    
       Even if we could theoretically adjust this behaviour of pygolang at python
       level to match Python3, there are also C++ and pyx/nogil worlds. And we want gil
       and nogil worlds to interoperate (see https://pypi.org/project/pygolang/#cython-nogil-api),
       so that e.g. if completely nogil code happens to run on the main thread,
       signal handling is still possible, even if that signal handling was setup at
       python level.
    
    With signals delivered to nogil channels both nogil world and python
    world can setup signal handlers and to be notified of them irregardles
    of whether main python thread is currently blocked in nogil wait or not.
    
    /reviewed-on !17
    e18adbab
Name
Last commit
Last update
..
_patch Loading commit data...
cmd Loading commit data...
os Loading commit data...
pyx Loading commit data...
runtime Loading commit data...
testdata/src/lab.nexedi.com/kirr Loading commit data...
testprog Loading commit data...
x Loading commit data...
.gitignore Loading commit data...
__init__.pxd Loading commit data...
__init__.py Loading commit data...
_context.pxd Loading commit data...
_context.pyx Loading commit data...
_cxx_test.pyx Loading commit data...
_errors.pxd Loading commit data...
_errors.pyx Loading commit data...
_errors_test.pyx Loading commit data...
_fmt.pxd Loading commit data...
_fmt.pyx Loading commit data...
_fmt_test.pyx Loading commit data...
_golang.pxd Loading commit data...
_golang.pyx Loading commit data...
_golang_test.pyx Loading commit data...
_gopath.py Loading commit data...
_gopath_test.py Loading commit data...
_io.pxd Loading commit data...
_io.pyx Loading commit data...
_os.pxd Loading commit data...
_os.pyx Loading commit data...
_os_test.pyx Loading commit data...
_strings_test.pyx Loading commit data...
_sync.pxd Loading commit data...
_sync.pyx Loading commit data...
_sync_test.pyx Loading commit data...
_testing.h Loading commit data...
_time.pxd Loading commit data...
_time.pyx Loading commit data...
context.cpp Loading commit data...
context.h Loading commit data...
context.pxd Loading commit data...
context.py Loading commit data...
context_test.py Loading commit data...
cxx.h Loading commit data...
cxx.pxd Loading commit data...
cxx_test.cpp Loading commit data...
cxx_test.py Loading commit data...
errors.cpp Loading commit data...
errors.h Loading commit data...
errors.pxd Loading commit data...
errors.py Loading commit data...
errors_test.cpp Loading commit data...
errors_test.py Loading commit data...
fmt.cpp Loading commit data...
fmt.h Loading commit data...
fmt.pxd Loading commit data...
fmt.py Loading commit data...
fmt_test.cpp Loading commit data...
fmt_test.py Loading commit data...
gcompat.py Loading commit data...
golang_test.py Loading commit data...
io.cpp Loading commit data...
io.h Loading commit data...
io.pxd Loading commit data...
io.py Loading commit data...
io_test.py Loading commit data...
libgolang.h Loading commit data...
os.cpp Loading commit data...
os.h Loading commit data...
os.pxd Loading commit data...
os_test.cpp Loading commit data...
os_test.py Loading commit data...
strconv.py Loading commit data...
strconv_test.py Loading commit data...
strings.cpp Loading commit data...
strings.h Loading commit data...
strings.pxd Loading commit data...
strings_test.cpp Loading commit data...
strings_test.py Loading commit data...
sync.cpp Loading commit data...
sync.h Loading commit data...
sync.pxd Loading commit data...
sync.py Loading commit data...
sync_test.cpp Loading commit data...
sync_test.py Loading commit data...
syscall.py Loading commit data...
testing.py Loading commit data...
time.cpp Loading commit data...
time.h Loading commit data...
time.pxd Loading commit data...
time.py Loading commit data...
time_test.py Loading commit data...