Skip to content

larsks/python-signalfd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.select, select.poll, and so forth).

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

Requirements

You will need the cffi module for Python.

Examples

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

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

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 = fd.info()
            print 'received signal %d' % info.ssi_signo

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

License

signalfd for Python Copyright (C) 2013 Lars Kellogg-Stedman lars@oddbit.com

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 http://www.gnu.org/licenses/.

About

signalfd() wrapper for Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages