Skip to content

fix some regressions from python 3.14 - #96

Merged
tridge merged 3 commits into
dronecan:masterfrom
tridge:pr-py314-fix
May 28, 2026
Merged

tridge merged 3 commits into
dronecan:masterfrom
tridge:pr-py314-fix

Conversation

@tridge

@tridge tridge commented May 28, 2026

Copy link
Copy Markdown
Member

fixes examples and tools, and has cleaner shutdown on control-C

tridge and others added 3 commits May 29, 2026 08:50
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>
@tridge
tridge merged commit 1a381e3 into dronecan:master May 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant