Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose signalfd(2) in the signal module #56513

Closed
vstinner opened this issue Jun 9, 2011 · 6 comments
Closed

expose signalfd(2) in the signal module #56513

vstinner opened this issue Jun 9, 2011 · 6 comments
Labels
extension-modules C modules in the Modules dir

Comments

@vstinner
Copy link
Member

vstinner commented Jun 9, 2011

BPO 12304
Nosy @vstinner, @giampaolo, @vadmium
Files
  • signalfd-4.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2015-03-18.11:00:29.089>
    created_at = <Date 2011-06-09.23:00:56.330>
    labels = ['extension-modules']
    title = 'expose signalfd(2) in the signal module'
    updated_at = <Date 2015-03-18.11:00:29.088>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2015-03-18.11:00:29.088>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-03-18.11:00:29.089>
    closer = 'vstinner'
    components = ['Extension Modules']
    creation = <Date 2011-06-09.23:00:56.330>
    creator = 'vstinner'
    dependencies = []
    files = ['22305']
    hgrepos = []
    issue_num = 12304
    keywords = ['patch']
    message_count = 6.0
    messages = ['138034', '138035', '138040', '161212', '196714', '238411']
    nosy_count = 7.0
    nosy_names = ['exarkun', 'vstinner', 'giampaolo.rodola', 'nadeem.vawda', 'neologix', 'rosslagerwall', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue12304'
    versions = ['Python 3.4']

    @vstinner
    Copy link
    Member Author

    vstinner commented Jun 9, 2011

    "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 bpo-8407 (msg103182). I created the issue because bpo-8407 contains much more than signalfd().

    @vstinner vstinner added the extension-modules C modules in the Modules dir label Jun 9, 2011
    @vstinner
    Copy link
    Member Author

    vstinner commented Jun 9, 2011

    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)
        )

    @vstinner
    Copy link
    Member Author

    vstinner commented Jun 9, 2011

    bpo-8407 changed the wakeup fd: it now contains the signal number. pthread_sigmask() is now part of Python 3.3 (see also bpo-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.

    @rosslagerwall
    Copy link
    Mannequin

    rosslagerwall mannequin commented May 20, 2012

    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...

    @vstinner
    Copy link
    Member Author

    vstinner commented Sep 1, 2013

    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.

    @vstinner
    Copy link
    Member Author

    vstinner commented Mar 18, 2015

    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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant