option to not override signal handler
- Ngôn ngữ chính
- Python
- Star
- 734
- Fork
- 412
- Merge trung bình
- 1 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 8
Mô tả
See also https://github.com/jupyter/qtconsole/issues/490
Hey there,
how can I embed qtconsole into an application without it overriding my own application's custom sigint handler?
Assume you have code that does
```
std::signal(SIGINT, &handleSigInt);
...
// do not initialize signal handlers
const auto initsigs = 0;
Py_InitializeEx(initsigs);
```
Then it is embedding qtconsole eventually, but at that point the sigint handler will be unset:
```
Thread 1 "QiTissue" hit Breakpoint 3, __interceptor_sigaction (signum=2, act=0x7fffffff8a60, oldact=0x7fffffff8b00)
at /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_signal_interceptors.inc:55
55 in /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_signal_interceptors.inc
(gdb) bt
#0 __interceptor_sigaction(int, __sanitizer::__sanitizer_sigaction const*, __sanitizer::__sanitizer_sigaction*)
(signum=2, act=0x7fffffff8a60, oldact=0x7fffffff8b00)
at /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_signal_interceptors.inc:55
#1 0x00007fff5c055f0f in PyOS_setsig (sig=sig@entry=2, handler=handler@entry=0x7fff5c0b6fec )
at Python/pylifecycle.c:2536
#2 0x00007fff5c0b849f in signal_signal_impl
(module=, handler=, signalnum=2) at ./Modules/signalmodule.c:505
#3 signal_signal (module=, args=, nargs=)
at ./Modules/clinic/signalmodule.c.h:141
#4 0x00007fff5bf7bbf8 in cfunction_vectorcall_FASTCALL
(func=, args=0x7fff58a24a88, nargsf=, kwnames=) at Objects/methodobject.c:426
```
or in python terms:
```
(gdb) py-bt
Traceback (most recent call first):
File "/usr/lib/python3.9/signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
File "/home/milian/.local/lib/python3.9/site-packages/ipykernel/kernelbase.py", line 280, in pre_handler_hook
self.saved_sigint_handler = signal(SIGINT, default_int_handler)
File "/home/milian/.local/lib/python3.9/site-packages/ipykernel/kernelbase.py", line 257, in dispatch_shell
self.pre_handler_hook()
```
the kernelbase.py code seems to reset the signal handler unconditionally to some default which is highly unexpected to me:
```
def pre_handler_hook(self):
"""Hook to execute before calling message handler"""
# ensure default_int_handler during handler call
self.saved_sigint_handler = signal(SIGINT, default_int_handler)
```
Is there a way to prevent this from happening?
Hướng dẫn đóng góp
Hướng nghiên cứu
Start in ipykernel/kernelbase.py at pre_handler_hook and trace how dispatch_shell invokes it. Determine how an embedding application could opt out of replacing its SIGINT handler, then verify that the custom handler remains intact while normal kernel signal handling still works.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100