tapmap.lifecycle
tapmap.lifecycle
Application lifecycle coordination: shutdown signaling and the server thread.
request_shutdown() is the single entry point every shutdown trigger (signal, UI action, or the server thread exiting unexpectedly) calls; only the main thread, via wait_for_shutdown() returning, ever acts on it.
logger = logging.getLogger(__name__)
module-attribute
_WAIT_POLL_S = 0.5
module-attribute
LifecycleCoordinator
Coordinate shutdown requests across threads.
Source code in src/tapmap/lifecycle.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
set_tray_icon(icon)
Register the running tray icon so request_shutdown() can also stop it.
Source code in src/tapmap/lifecycle.py
36 37 38 | |
request_shutdown()
Signal that the application should shut down. Safe from any thread, idempotent.
Source code in src/tapmap/lifecycle.py
40 41 42 43 44 | |
run_tray(icon, *, on_ready=None)
Run icon's blocking loop, honoring a shutdown already requested before it started.
pystray's Icon.stop() has no effect until the icon is actually running, so a shutdown requested between set_tray_icon() and this call (e.g. the server thread dying immediately) would otherwise be lost, and icon.run() would then block forever. pystray only invokes the setup callback once it has marked the icon running, so re-checking and re-stopping there closes that window.
If provided, on_ready runs from pystray's setup callback after the icon has been marked ready.
Source code in src/tapmap/lifecycle.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
wait_for_shutdown()
Block the calling thread until shutdown has been requested.
Source code in src/tapmap/lifecycle.py
77 78 79 80 81 82 83 | |
install_signal_handlers()
Register SIGINT/SIGTERM handlers that request shutdown.
Source code in src/tapmap/lifecycle.py
85 86 87 88 89 90 91 92 | |
_start_windows_message_loop_nudge()
Start a periodic Windows timer that wakes pystray's blocking message loop, or None.
Source code in src/tapmap/lifecycle.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
_stop_windows_message_loop_nudge(timer_id)
Remove the timer started by _start_windows_message_loop_nudge(), if one was created.
Source code in src/tapmap/lifecycle.py
113 114 115 116 | |
start_server_thread(server, coordinator)
Run server.serve_forever() on a background thread; request shutdown when it exits.
Source code in src/tapmap/lifecycle.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |