signalfd() wrapper for Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

signalfd for Python

This is a cffi based module for Python that makes available the signalfd() system call, as well as all of sigsetops(3). The signalfd() calls allows your code to receive signals via a file descriptor, rather than via the normal asynchronous delivery method, which makes signals much more compatible with event based solutions (such as those using, select.poll, and so forth).

For details, please see the signalfd(2) man page.


You will need the cffi module for Python.


import sys
import signal
import select
from signalfd import signalfd, sigset

# Create a signal set containing all signals.
mask = sigset()

with signalfd(mask) as fd:
    poll = select.poll()
    poll.register(fd,  select.POLLIN)
    poll.register(sys.stdin, select.POLLIN)

    # Print signals as they are received until user presses
    # <RETURN>.
    while True:
        events = dict(poll.poll())

        if fd.fileno() in events:
            info =
            print 'received signal %d' % info.ssi_signo

        if sys.stdin.fileno() in events:
            print 'all done'


signalfd for Python Copyright (C) 2013 Lars Kellogg-Stedman

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see