Python gi.repository.GLib 模块,unix_signal_add() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用gi.repository.GLib.unix_signal_add()

项目:Projects    作者:SilverLuke    | 项目源码 | 文件源码
def InitSignal(gui):
    def signal_action(signal):
        if signal.value is signal.SIGINT.value:
            print("\r", end="")
            logging.debug("Caught signal SIGINT(2)")
        gui.stop()

    def handler(*args):
        signal_action(args[0])

    def idle_handler(*args):
        GLib.idle_add(signal_action, priority=GLib.PRIORITY_HIGH)

    def install_glib_handler(sig):
        GLib.unix_signal_add(GLib.PRIORITY_HIGH, sig, handler, sig)

    SIGS = [getattr(signal, s, None) for s in "SIGINT".split()]
    for sig in filter(None, SIGS):
        signal.signal(sig, idle_handler)
        GLib.idle_add(install_glib_handler, sig, priority=GLib.PRIORITY_HIGH)
项目:co2monitor    作者:nobodyinperson    | 项目源码 | 文件源码
def setup_signals(self, signals, handler):
        """
        This is a workaround to signal.signal(signal, handler)
        which does not work with a GLib.MainLoop() for some reason.
        Thanks to: http://stackoverflow.com/a/26457317/5433146
        args:
            signals (list of signal.SIG... signals): the signals to connect to
            handler (function): function to be executed on these signals
        """
        def install_glib_handler(sig): # add a unix signal handler
            GLib.unix_signal_add( GLib.PRIORITY_HIGH, 
                sig, # for the given signal
                handler, # on this signal, run this function
                sig # with this argument
                )

        for sig in signals: # loop over all signals
            GLib.idle_add( # 'execute'
                install_glib_handler, sig, # add a handler for this signal
                priority = GLib.PRIORITY_HIGH  )

    # set the config
项目:co2monitor    作者:nobodyinperson    | 项目源码 | 文件源码
def setup_signals(self, signals, handler):
        """
        This is a workaround to signal.signal(signal, handler)
        which does not work with a GLib.MainLoop() for some reason.
        Thanks to: http://stackoverflow.com/a/26457317/5433146
        args:
            signals (list of signal.SIG... signals): the signals to connect to
            handler (function): function to be executed on these signals
        """
        def install_glib_handler(sig): # add a unix signal handler
            GLib.unix_signal_add( GLib.PRIORITY_HIGH, 
                sig, # for the given signal
                handler, # on this signal, run this function
                sig # with this argument
                )

        for sig in signals: # loop over all signals
            GLib.idle_add( # 'execute'
                install_glib_handler, sig, # add a handler for this signal
                priority = GLib.PRIORITY_HIGH  )

    # build the gui
项目:simbuto    作者:nobodyinperson    | 项目源码 | 文件源码
def setup_signals(self, signals, handler):
        """
        This is a workaround to signal.signal(signal, handler)
        which does not work with a GLib.MainLoop() for some reason.
        Thanks to: http://stackoverflow.com/a/26457317/5433146
        args:
            signals (list of signal.SIG... signals): the signals to connect to
            handler (function): function to be executed on these signals
        """
        def install_glib_handler(sig): # add a unix signal handler
            GLib.unix_signal_add( GLib.PRIORITY_HIGH, 
                sig, # for the given signal
                handler, # on this signal, run this function
                sig # with this argument
                )

        for sig in signals: # loop over all signals
            GLib.idle_add( # 'execute'
                install_glib_handler, sig, # add a handler for this signal
                priority = GLib.PRIORITY_HIGH  )

    # get an object from the builder
项目:eos-data-distribution    作者:endlessm    | 项目源码 | 文件源码
def main():
    utils.parse_args(include_name=False)
    loop = GLib.MainLoop()

    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, signal_cb)
    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGTERM, signal_cb)
    monitor = Gio.VolumeMonitor.get()
    store = simple_store.Producer(prefix=SUBSCRIPTIONS_SOMA,
                                  base=defaults.ENDLESS_NDN_CACHE_PATH,
                                  cost=defaults.RouteCost.USB)
    store.start()
    for mount in monitor.get_mounts():
        mount_added_cb(monitor, mount, store)
    monitor.connect("mount-added", mount_added_cb, store)
    monitor.connect("mount-removed", mount_removed_cb, store)

    maybe_time_out()

    loop.run()
项目:stickies    作者:aboudzakaria    | 项目源码 | 文件源码
def SignalHandler(app):
    def signal_action(signal):
        if signal is 1: print("Caught signal SIGHUP(1)")
        elif signal is 2: print("Caught signal SIGINT(2)")
        elif signal is 15: print("Caught signal SIGTERM(15)")
        app.exit_gracefully()

    def handler(*args):
        # Activate GLib signal handler
        signal_action(args[0])

    def idle_handler(*args):
        # Activate python signal handler
        GLib.idle_add(signal_action, priority=GLib.PRIORITY_HIGH)

    def install_glib_handler(sig):
        unix_signal_add = None
        if hasattr(GLib, "unix_signal_add"):
            unix_signal_add = GLib.unix_signal_add
        elif hasattr(GLib, "unix_signal_add_full"):
            unix_signal_add = GLib.unix_signal_add_full
        if unix_signal_add:
            # Register GLib signal handler
            unix_signal_add(GLib.PRIORITY_HIGH, sig, handler, sig)
        else:
            print("WARNING: Can't install GLib signal handler, too old gi.")

    SIGS = [getattr(signal, s, None) for s in "SIGINT SIGTERM SIGHUP".split()]
    for sig in filter(None, SIGS):
        # Register Python signal handler
        signal.signal(sig, idle_handler)
        GLib.idle_add(install_glib_handler, sig, priority=GLib.PRIORITY_HIGH)
项目:ImunesExperimentExporter    作者:patriziotufarolo    | 项目源码 | 文件源码
def install_glib_handler(sig):
    unix_signal_add = None
    if hasattr(GLib, "unix_signal_add"):
        unix_signal_add = GLib.unix_signal_add
    elif hasattr(GLib, "unix_signal_add_full"):
        unix_signal_add = GLib.unix_signal_add_full
    if unix_signal_add:
        unix_signal_add(GLib.PRIORITY_HIGH, sig, handler, sig)
    else:
        print("Can't user Glib signal handler")