Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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()
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()
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:
)
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()
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()
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()
def __getattr__(cls, name):
return getattr(_signal_module, name)
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")
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)