Exemplo n.º 1
0
 def test_sigmask_restore(self):
     empty = sigfd.sigset()
     orig = sigfd.sigprocmask(empty)
     mask = sigfd.sigset()
     mask.add(signal.SIGHUP)
     mask.add(signal.SIGINT)
     with sigfd.sigfd(mask) as fd:
         pass
     final = sigfd.sigprocmask(empty)
     assert orig.get_set() == final.get_set()
     print(final.get_set())
     print(orig.get_set())
Exemplo n.º 2
0
 def test_sigset_membership(self):
     signals = sigfd.sigset()
     signals.add(signal.SIGHUP)
     signals.add(signal.SIGINT)
     assert signals.ismember(signal.SIGHUP)
     assert signals.ismember(signal.SIGINT)
     signals.remove(signal.SIGINT)
     assert not signals.ismember(signal.SIGINT)
Exemplo n.º 3
0
    def test_alarm(self):
        mask = sigfd.sigset()
        mask.add(signal.SIGALRM)

        with sigfd.sigfd(mask) as fd:
            poll=select.poll()
            poll.register(fd, select.POLLIN)
            signal.alarm(1)
            events = dict(poll.poll(2000))
            assert fd.fileno() in events
            assert fd.info().ssi_signo == signal.SIGALRM
Exemplo n.º 4
0
 def test_signalfd_create(self):
     signals = sigfd.sigset()
     assert sigfd.sigfd(signals) is not None
Exemplo n.º 5
0
 def test_sigset_create(self):
     assert sigfd.sigset() is not None
Exemplo n.º 6
0
The URL for this example:
https://github.com/larsks/python-signalfd/raw/master/example.py

References:
http://blog.oddbit.com/2013/11/28/a-python-interface-to-signalfd/
https://github.com/larsks/python-signalfd/tree/master/signalfd
[email protected]:larsks/python-signalfd.git
'''

import os # for getpid
import sys # for stdin
import select # for poll, POLLIN
import sigfd # for sigset, sigfd

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

with sigfd.sigfd(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>.

    print('=' * 70)
    print('Send signals to this process (%d) or press RETURN to exit.' % os.getpid())
    print('=' * 70)

    while True:
        events = dict(poll.poll())