This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: expose signalfd(2) in the signal module
类型: Stage: patch review
Components: Extension Modules Versions: Python 3.4
process
状态: closed Resolution: out of date
Dependencies: 后续:
分配给: 抄送列表: exarkun, giampaolo.rodola, martin.panter, nadeem.vawda, neologix, rosslagerwall, vstinner
优先级: normal 关键字: patch

Created on 2011-06-09 23:00 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

文件
文件名 上传时间 Description 编辑
signalfd-4.patch vstinner, 2011-06-09 23:02
Messages (6)
msg138034 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2011-06-09 23:00
"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 (msg103182). I created the issue because #8407 contains much more than signalfd().
msg138035 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2011-06-09 23:02
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 (msg135438):

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)
    )
msg138040 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2011-06-09 23:40
#8407 changed the wakeup fd: it now contains the signal number. pthread_sigmask() is now part of Python 3.3 (see also #8407).

signalfd() has advantages over the wakeup fd (msg103326):

 - it is handled in the kernel, the process is not interrupted. For example, system calls cannot fail with EINTR.
 - it gives much more information than the signal number (see signalfd_siginfo structure)
 - it is also possible to have several signalfds, each with a different signal mask. set_wakeup_fd is limited to a single fd per-process.
msg161212 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) 日期: 2012-05-20 15:04
Patch seems good (although it doesn't apply cleanly).

Why do you not provide a structure to decode the bytes? I thought relying on ctypes in the stdlib was not advised...
msg196714 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2013-09-01 07:37
> Why do you not provide a structure to decode the bytes? I thought relying
on ctypes in the stdlib was not advised...

We should expose it. The ctypes was just a poof of concept.
msg238411 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2015-03-18 11:00
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
历史
日期 用户 动作 参数
2022-04-11 14:57:18admin修改github: 56513
2015-03-18 11:00:29vstinner修改状态: open -> closed
resolution: out of date
消息: + msg238411
2015-02-08 03:02:36martin.panter修改抄送: + martin.panter
2013-09-01 07:37:02vstinner修改消息: + msg196714
2013-08-31 18:58:52giampaolo.rodola修改抄送: + giampaolo.rodola
2013-08-31 12:32:22pitrou修改versions: + Python 3.4, - Python 3.3
2012-05-20 15:04:14rosslagerwall修改抄送: + rosslagerwall
消息: + msg161212
2012-05-16 15:56:23pitrou修改抄送: + neologix

stage: patch review
2011-06-10 06:41:34nadeem.vawda修改抄送: + nadeem.vawda
2011-06-09 23:40:57vstinner修改消息: + msg138040
2011-06-09 23:02:34vstinner修改文件: + signalfd-4.patch
keywords: + patch
消息: + msg138035
2011-06-09 23:00:56vstinner创建