Issue 12304: expose signalfd(2) in the signal module (original) (raw)
"Linux offers the signalfd syscall since 2.6.22 (with minor changes afterwards). This call allows signals to be handled as bytes read out of a file descriptor, rather than as interruptions to the flow of a program. Quite usefully, this file descriptor can be select()'d on (or poll()'d, epoll()'d, etc) alongside other "normal" file descriptors.
In order to effectively use signalfd(), the signals in question must be blocked, though. So it makes sense to expose sigprocmask(2) at the same time, in order to allow this blocking to be set up."
This message is copy/pasted from #8407 (). I created the issue because #8407 contains much more than signalfd().
signalfd-4.patch: my more recent patch exposing signalfd(). It lacks a structure to decode the bytes read from the signalfd file descriptor. Example in ctypes ():
class signalfd_siginfo(Structure): fields = ( ('ssi_signo', c_uint32), # Signal number ('ssi_errno', c_int32), # Error number (unused) ('ssi_code', c_int32), # Signal code ('ssi_pid', c_uint32), # PID of sender ('ssi_uid', c_uint32), # Real UID of sender ('ssi_fd', c_int32), # File descriptor (SIGIO) ('ssi_tid', c_uint32), # Kernel timer ID (POSIX timers) ('ssi_band', c_uint32), # Band event (SIGIO) ('ssi_overrun', c_uint32), # POSIX timer overrun count ('ssi_trapno', c_uint32), # Trap number that caused signal ('ssi_status', c_int32), # Exit status or signal (SIGCHLD) ('ssi_int', c_int32), # Integer sent by sigqueue(2) ('ssi_ptr', c_uint64), # Pointer sent by sigqueue(2) ('ssi_utime', c_uint64), # User CPU time consumed (SIGCHLD) ('ssi_stime', c_uint64), # System CPU time consumed (SIGCHLD) ('ssi_addr', c_uint64), # Address that generated signal # (for hardware-generated signals) ('_padding', c_char * 46), # Pad size to 128 bytes (allow for # additional fields in the future) )
signalfd is very useful for event-driven frameworks like Twisted or asyncio. asyncio doesn't use it, and I didn't see any request to support it yet. asyncio uses signal.set_wakeup_fd() which looks to be enough, and it is now available on all platforms (including Windows).
I'm not interested to write the structure to unpack the 128 bytes structure of signalfd, nor to update my patch. I just close the issue.
Reopen the issue or open a new one if you are interested by signalfd.
Anyway, there is already a third-party Python module providing signalfd() for Python 2 and Python 3: https://pypi.python.org/pypi/python-signalfd