···43 if event_count % 2500 == 0:
44 feed_manager.commit_changes()
4546-async def shutdown(signal, loop):
47- logger.info(f'received exit signal {signal.name}')
000000048 feed_manager.stop_all()
49 tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
50 [task.cancel() for task in tasks]
···58 for sig in catch_signals:
59 loop.add_signal_handler(
60 sig,
61- lambda s=sig: asyncio.create_task(shutdown(s, loop))
62 )
06364 try:
65 loop.create_task(main())
···43 if event_count % 2500 == 0:
44 feed_manager.commit_changes()
4546+def handle_exception(loop, context):
47+ msg = context.get("exception", context["message"])
48+ logger.error(f"Caught exception: {msg}")
49+ logger.info("Shutting down...")
50+ asyncio.create_task(shutdown(loop))
51+52+async def shutdown(loop, signal=None):
53+ if signal:
54+ logger.info(f'received exit signal {signal.name}')
55 feed_manager.stop_all()
56 tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
57 [task.cancel() for task in tasks]
···65 for sig in catch_signals:
66 loop.add_signal_handler(
67 sig,
68+ lambda s=sig: asyncio.create_task(shutdown(loop, signal=s))
69 )
70+ loop.set_exception_handler(handle_exception)
7172 try:
73 loop.create_task(main())