Repository navigation
fix some regressions from python 3.14 - #96
Merged
Merged
Conversation
Python 3.14 changed the default multiprocessing start method on Linux from 'fork' to 'forkserver'. Under forkserver/spawn, Process.start() must not be called while the __main__ module is still being imported, and the __main__ module is re-imported in the helper process. The bridge tool and the example scripts created CAN drivers/nodes (which spawn an IO process) at module top level, so they crashed with "An attempt has been made to start a new process before the current process has finished its bootstrapping phase". Wrap the executable body of each script in a main() function guarded by 'if __name__ == "__main__":', with handlers as nested closures so their references to node/args still resolve. Convert top-level 'global' to 'nonlocal' where a handler reassigns an enclosing variable. Also guard MAVCAN.close() with proc.is_alive() (mirroring SLCAN) so a never-started process no longer raises "can only join a started process" from __del__, which masked the real error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Python 3.14 changed the default multiprocessing start method on Linux from 'fork' to 'forkserver'. The MAVCAN and SLCAN IO processes guard their main loop with `os.getppid() == parent_pid` to die when the parent exits. Under forkserver the IO process is forked from the fork-server, so getppid() returns the fork-server's pid, never the parent's. The guard then fires on the first iteration: MAVCAN enabled CAN forwarding once and exited before reading any CAN_FRAME, so the bridge reported 0 pkts/sec while dronecan_gui_tool (which forces the 'spawn' start method) worked. Probe the recorded parent pid directly with os.kill(parent_pid, 0) instead, which is correct regardless of start method. Also carry the SIGINT-ignore and daemon-thread cleanups for the IO processes and the bridge tool. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The mcast IO process ignores SIGINT (so Ctrl-C is handled by the parent), but close() was a no-op and the child had no exit queue or parent-liveness check. If the parent caught Ctrl-C and kept running, or was hard-killed, the mcast_io_process could linger with its socket open. Mirror MAVCAN/SLCAN: pass an exit_queue and the parent pid to the child, check both at the top of the loop (via parent_process_alive(), which uses os.kill(parent_pid, 0) so it is correct under the forkserver start method), and make close() signal QUIT and join the process. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes examples and tools, and has cleaner shutdown on control-C