GithubHelp home page GithubHelp logo

ossobv / pysigset Goto Github PK

View Code? Open in Web Editor NEW
12.0 7.0 5.0 18 KB

Python blocking/suspending signals under Linux/OSX using ctypes sigprocmask access

Python 91.52% Makefile 8.48%
python library signals sigprocmask

pysigset's Introduction

pysigset, signal blocking under GNU/Linux & OS X

Provides access to sigprocmask(2) and friends and convenience wrappers to python application developers wanting to SIG_BLOCK and SIG_UNBLOCK signals in critical sections of their code.

Most common usage

from signal import SIGINT, SIGTERM
from pysigset import suspended_signals

with suspended_signals(SIGINT, SIGTERM):
    # Signals are blocked here..
    pass
# Any pending signal is fired now..

Also available

sigaddset(*args)
    int sigaddset(sigset_t *set, int signum)

sigdelset(*args)
    int sigdelset(sigset_t *set, int signum)

sigemptyset(*args)
    int sigemptyset(sigset_t *set)

sigfillset(*args)
    int sigfillset(sigset_t *set)

sigismember(*args)
    int sigismember(const sigset_t *set, int signum)

sigpending(*args)
    int sigpending(sigset_t *set)

sigprocmask(*args)
    int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)

sigsuspend(*args)
    int sigsuspend(const sigset_t *mask)

Similar tools

python-signalfd provides access to sigprocmask and signalfd. Its advantage is access to signalfd. Its disadvantage is a compilation requirement.

pysigset has a pythonic interface and requires only ctypes access to libc.so.6 or libSystem.B.dylib.

Changes

2021-05-03: 0.4.0

  • Change License to LGPL 3.

2015-09-22: 0.3.2

  • Python 3 compatibility (thanks Kevin Pouget).
  • Update version, update trove classifiers; adding Python 3, moving to Production/Stable.

2015-05-23: 0.2.2

  • Fix so we can install using setup.py again.

2013-07-30: 0.2.1

  • Fix so the RST is displayed on PyPI.

2013-07-30: 0.2

  • Add support for OS X / Darwin (thanks Dan Sully (dsully))
  • Add support for easy uploading to PyPI.

2013-04-15: 0.1

  • Initial release.

Copyright 2013-2021, Walter Doekes (OSSO B.V.)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser 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 Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.

pysigset's People

Contributors

kpouget avatar wdoekes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pysigset's Issues

Move main() code into test_ file

Moving the main() code to a test_pysigset.py file makes sense:

  • better BCH points
  • less code loaded into memory which we're not using

Don't forget to update pysigset version and pushing to pypi when fixing stuff.

Refactor SIGSET.__repr__() to call other methods

def __repr__(self):
    human_sigs = _get_human_signals()
    return '{%s}' % (', '.join(ret),)
def _get_human_signals(self):
        ret = []
        for i, bitmask in enumerate(self.val):
            if bitmask:
                ret.extend(self._get_XXX(mask2list, i, bitmask)
    return ret
def _get_XXX(...):
                if mask2list and i <= 1:  # 64 bits in the first two int32s
                    numbers = mask2list(bitmask)  # sorted from low to high
                    if i == 1:
                        numbers = [i << 1 for i in numbers]
                    for number in numbers:
                        ret.append(SIGNAMES.get(number, 'SIG%d' % (number,)))
                else:
                    strvalue = binrepr and binrepr(bitmask) or str(bitmask)
                    ret.append('%d: %s' % (i, strvalue))
    return ret

Or something..

Add __doc__ setting to _wrap() function

sigemptyset = _wrap(libc.sigemptyset, [0])
sigemptyset.__doc__ = 'int sigemptyset(sigset_t *set)'

This could be:

sigemptyset = _wrap(
    libc.sigemptyset, [0], 'int sigemptyset(sigset_t *set)')

Make BCH happy by removing two "code" lookalikes

else:  # platform.system() == 'Linux'

Replace with "is" or something, so it doesn't think the code is "removed".

Same with:

Copyright 2013-2015, Walter Doekes (OSSO B.V.) <wjdoekes osso nl>

It thinks that is code. Replace with e-mail address with + in it?

please improve examples in documentation

It is not clear to me how to instantiate a sigset in order to then pass it to pysigset.sigaddset(). Please could you improve the examples in the "Most common usage" section to cover instantiation of a sigset (mysigset = ???) and a call to sigsetadd() (??? = sigsetadd(mysigset???, signal.SIGCHLD???) Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.