pytweezer.servers.process_cleanup module

Cross-platform cleanup for orphaned pytweezer server/device/logger processes.

Every managed process is spawned as ['python3', <script>, <name>] (see bin/managed_panel.py/bin/process_tile_base.py). If the GUI that launched them is killed rather than closed normally, these children can outlive it and keep holding their ZMQ sockets, so the next pytweezer-server/pytweezer-client launch fails to bind with “Address already in use”. kill_stale_processes() finds and kills any such leftover process by matching its command line against the script paths in CONFIG["Servers"]/["Devices"]/["Loggers"].

This matches on process, not socket, so it also catches the pure-ZMQ- subscriber loggers that never bind a listening port at all.

xsub_xpub.py’s own _terminate_stale_instances does something similar but POSIX-only (it scans /proc) and only for hub instances of the same name about to start. This module is the general, cross-platform version meant to be run on demand, from any PC role, against every managed category.

pytweezer.servers.process_cleanup.find_stale_processes()[source]

Return (pid, category, name, commandline) for every running process whose command line matches a configured server/device/logger script, excluding this process itself.

pytweezer.servers.process_cleanup.kill_stale_processes(grace_s=2.0, dry_run=False)[source]

Find and terminate every stale pytweezer server/device/logger process.

Returns the (pid, category, name, commandline) list that was (or, if dry_run, would be) killed.