How to use the gevent.signal function in gevent

To help you get started, we’ve selected a few gevent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github th3sys / transfixed / test_gain / logon.py View on Github external
def main():

    try:
        gevent.joinall([
            gevent.spawn(start()),
            gevent.spawn(poll()),
        ])

    except (fix.ConfigError, fix.RuntimeError) as e:
        logger.error(e)


if __name__ == '__main__':
    gevent.signal(signal.SIGQUIT, gevent.kill)
    main()
github HydraChain / hydrachain / hydrachain / app.py View on Github external
def serve_until_stopped(*apps):
    # wait for interrupt
    evt = Event()
    gevent.signal(signal.SIGQUIT, evt.set)
    gevent.signal(signal.SIGTERM, evt.set)
    evt.wait()
    # finally stop
    for app in apps:
        app.stop()
github raiden-network / raiden / tools / app.py View on Github external
return gevent.spawn(
                transfer, amount_per_transfer, peer
            )

        greenlets = []
        for channel, amount in transfers_by_channel.items():
            greenlets.append(transfer(token_address, 1, amount, channel))

        gevent.joinall(greenlets)

    else:
        # wait for interrupt
        event = gevent.event.Event()
        gevent.signal(signal.SIGQUIT, event.set)
        gevent.signal(signal.SIGTERM, event.set)
        gevent.signal(signal.SIGINT, event.set)
        event.wait()

    app.stop()
github simplecrypto / powerpool / powerpool / main.py View on Github external
comp.start()

        # Starts the greenlet
        Component.start(self)
        # Start the datagram control server if it's been inited
        if self.config['datagram']['enabled']:
            DatagramServer.start(self, )

        # This is the main thread of execution, so just continue here waiting
        # for exit signals
        ######
        # Register shutdown signals
        gevent.signal(signal.SIGUSR1, self.dump_objgraph)
        gevent.signal(signal.SIGHUP, exit, "SIGHUP")
        gevent.signal(signal.SIGINT, exit, "SIGINT")
        gevent.signal(signal.SIGTERM, exit, "SIGTERM")

        try:
            gevent.wait()
        # Allow a force exit from multiple exit signals (Ctrl+C mashed multiple times)
        finally:
            self.logger.info("Exiting requested, allowing {} seconds for cleanup."
                             .format(self.config['term_timeout']))
            try:
                for comp in self.components.itervalues():
                    self.logger.debug("Calling stop on component {}".format(comp))
                    comp.stop()
                if gevent.wait(timeout=self.config['term_timeout']):
                    self.logger.info("All threads exited normally")
                else:
                    self.logger.info("Timeout reached, shutting down forcefully")
            except gevent.GreenletExit:
github PaloAltoNetworks / minemeld-core / minemeld / traced / main.py View on Github external
)

    query_processor = minemeld.traced.queryprocessor.QueryProcessor(
        comm,
        store,
        config=config.get('queryprocessor', {})
    )

    shutdown_event = gevent.event.Event()
    comm.add_failure_listener(
        functools.partial(_ioloop_failure, shutdown_event)
    )

    comm.start()

    gevent.signal(signal.SIGINT, _sigint_handler)
    gevent.signal(signal.SIGTERM, _sigterm_handler)

    try:
        shutdown_event.wait()

    except KeyboardInterrupt:
        pass

    except:
        LOG.exception('Exception')

    finally:
        _cleanup()
github waawal / greenbalance / slask / udpforwarder.py View on Github external
def main():
    #args = sys.argv[1:]
    #if len(args) != 2:
    #    sys.exit('Usage: %s source-address destination-address' % __file__)
    source = parse_address("0.0.0.0:3001")
    #dest = parse_address(args[1])
    server = PortForwarder(source, destinationsdict)
    #log('Starting port forwarder %s:%s -> %s:%s', *(server.address[:2] + dest))
    gevent.signal(signal.SIGTERM, server.close)
    gevent.signal(signal.SIGQUIT, server.close)
    gevent.signal(signal.SIGINT, server.close)
    server.serve_forever()
github dividuum / fdb-nbd / fdb-nbd.py View on Github external
fdb.api_version(510)
    db = fdb.open()

    stores = Stores(db)

    # del db[:]

    stores.create('foobar', 1000000)
    stores.create('example', 1000000)

    for name in stores.list():
        print('store %s\n  nbd-client -N %s 127.0.0.1 /dev/nbd0' % (name, name))

    server = Server(('127.0.0.1', 10809), stores)
    gevent.signal(signal.SIGTERM, server.stop)
    gevent.signal(signal.SIGINT, server.stop)
    server.serve_forever()
github plivo / plivoframework / src / plivo / rest / freeswitch / outboundserver.py View on Github external
def start(self):
        self.log.info("Starting OutboundServer ...")
        # catch SIG_TERM
        gevent.signal(signal.SIGTERM, self.sig_term)
        gevent.signal(signal.SIGHUP, self.sig_hup)
        # run
        self._run = True
        if self._daemon:
            self.do_daemon()
        super(PlivoOutboundServer, self).start()
        self.log.info("OutboundServer started at '%s'" \
                                    % str(self.fs_outbound_address))
        self.serve_forever()
        self.log.info("OutboundServer Exited")
github Dallinger / Dallinger / dallinger / heroku / rq_gevent_worker.py View on Github external
def request_stop():
            if not self._stop_requested:
                gevent.signal(signal.SIGINT, request_force_stop)
                gevent.signal(signal.SIGTERM, request_force_stop)

                self.log.warning("Warm shut down requested.")
                self.log.warning(
                    "Stopping after all greenlets are finished. "
                    "Press Ctrl+C again for a cold shutdown."
                )

                self._stop_requested = True
                self.gevent_pool.join()
                if self.gevent_worker is not None:
                    self.gevent_worker.kill(StopRequested)