def setup_signal_handlers(shutdown_function: Callable[[], Coroutine[Any, Any, None]]) -> None: """ Make sure that shutdown_function is called when a SIGTERM or a SIGINT interrupt occurs. :param shutdown_function: The function that contains the shutdown logic. """ # ensure correct ioloop ioloop = IOLoop.current() def hard_exit() -> None: context_dump(ioloop) sys.stdout.flush() # Hard exit, not sys.exit # ensure shutdown when the ioloop is stuck os._exit(const.EXIT_HARD) def handle_signal(signum: signal.Signals, frame: Optional[FrameType]) -> None: # force shutdown, even when the ioloop is stuck # schedule off the loop t = Timer(const.SHUTDOWN_GRACE_HARD, hard_exit) t.daemon = True t.start() ioloop.add_callback_from_signal(safe_shutdown_wrapper, shutdown_function) def handle_signal_dump(signum: signal.Signals, frame: Optional[FrameType]) -> None: context_dump(ioloop) signal.signal(signal.SIGTERM, handle_signal) signal.signal(signal.SIGINT, handle_signal) signal.signal(signal.SIGUSR1, handle_signal_dump) if rpdb: rpdb.handle_trap()
def may_initialize_rpdb() -> None: """ On Linux only, import and initialize rpdb, to enable remote debugging if necessary. """ # rpdb signal trapping does not work on Windows, as there is no SIGTRAP: if not is_linux(): return import rpdb rpdb_port = 4444 rpdb.handle_trap(port=rpdb_port) # For some reason, os.getpid() does not return the ID of what appears to be the currently running process. logging.info("rpdb is handling traps. To debug: identify the main runner.py process, then as root: " f"kill -TRAP <process_id>; nc 127.0.0.1 {rpdb_port}")
import InfiniteGlass import Xlib.X import struct import pkg_resources import os.path import yaml import json if os.environ.get("GLASS_DEBUGGER", "") == "rpdb": import rpdb rpdb.handle_trap() rpdb.handle_trap() def main(*arg, **kw): configpath = os.path.expanduser( os.environ.get("GLASS_WIDGET_CONFIG", "~/.config/glass/widgets.json")) with open(configpath) as f: config = yaml.load(f, Loader=yaml.SafeLoader) with InfiniteGlass.Display() as display: for widget_type, widgets in config.items(): for name, widget in widgets.items(): w = display.root.create_window() properties = { "WM_CLASS": "data://glass-widget", "WM_NAME": "data://" + name, "_NET_WM_WINDOW_TYPE": "_NET_WM_WINDOW_TYPE_DESKTOP" } if widget_type == "widgets":