F
Member
Adding a process pool to a Python robotics application can expose a failure that never appears in the standalone algorithm test: workers start normally before acquisition, but hang or misbehave when launched after the camera, native inference runtime or communication stack has initialised.
The first diagnostic question should be how those worker processes start, and which resources are already live at that point. “Multiprocessing bypasses the GIL” is not an ownership or initialisation contract.
### A fork is not a clean application restart
With a fork-based start method, the child inherits the parent's process state, including resources that were not intended to become worker inputs. If another thread held a lock at the instant of the fork, the child can inherit a locked object without inheriting the thread that would release it. Native libraries may also have internal state that is not safe to use this way.
The official [Python multiprocessing documentation](https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods) explicitly warns that safely forking a multithreaded process is problematic. It distinguishes this from starting a fresh interpreter with `spawn` and from the `forkserver` approach. Record the actual selected method rather than assuming it from the operating system: Python version, application configuration and libraries can affect the context in use.
This is a candidate mechanism, not proof that every post-startup hang is caused by a fork. Queue shutdown, worker exceptions and blocked device calls need their own evidence.
### Reproduce the initialisation boundary
A controlled diagnostic matrix can separate algorithm failure from inherited-runtime failure:
- Run the worker computation on saved inputs without starting any devices.
- Create workers before and after initialising the native runtime, with actuation disconnected.
- Record process IDs, start method, import order and each initialisation stage.
- Capture parent and worker stack traces at the hang, including native stacks where available.
- Check which process opens, reads and closes each device or communication handle.
A successful early-start run is a clue, not a complete repair. Determine whether workers still depend on resources created later, and whether shutdown and restart follow the same ownership rules.
### Fresh interpreters expose a different class of mistakes
Changing to `spawn` does not make arbitrary application structure correct. The child imports modules in a fresh interpreter. Device creation at module import can therefore run again, causing several workers to contend for a camera or connection. The usual main-module guard protects startup code only if resource creation is actually behind that boundary.
Keep worker functions importable and give them explicit, serialisable inputs. If a worker needs its own supported native context, initialise that context inside the worker according to the library's rules. A dedicated acquisition process can instead own the device and exchange bounded work items with compute workers. That design needs an explicit queue and shutdown policy, not merely a larger pool.
Fresh startup and data serialisation have costs. Prestarting workers can reduce latency but complicate lifecycle coordination. Forkserver can avoid inheriting an already busy application process, yet imported or preloaded code still deserves review for side effects. No start method supplies a universal guarantee for every SDK.
**Open engineering question:** which process owns each live native runtime in your robotics application, and can you reproduce worker startup and shutdown without opening the same hardware twice or inheriting an unsupported context?
The first diagnostic question should be how those worker processes start, and which resources are already live at that point. “Multiprocessing bypasses the GIL” is not an ownership or initialisation contract.
### A fork is not a clean application restart
With a fork-based start method, the child inherits the parent's process state, including resources that were not intended to become worker inputs. If another thread held a lock at the instant of the fork, the child can inherit a locked object without inheriting the thread that would release it. Native libraries may also have internal state that is not safe to use this way.
The official [Python multiprocessing documentation](https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods) explicitly warns that safely forking a multithreaded process is problematic. It distinguishes this from starting a fresh interpreter with `spawn` and from the `forkserver` approach. Record the actual selected method rather than assuming it from the operating system: Python version, application configuration and libraries can affect the context in use.
This is a candidate mechanism, not proof that every post-startup hang is caused by a fork. Queue shutdown, worker exceptions and blocked device calls need their own evidence.
### Reproduce the initialisation boundary
A controlled diagnostic matrix can separate algorithm failure from inherited-runtime failure:
- Run the worker computation on saved inputs without starting any devices.
- Create workers before and after initialising the native runtime, with actuation disconnected.
- Record process IDs, start method, import order and each initialisation stage.
- Capture parent and worker stack traces at the hang, including native stacks where available.
- Check which process opens, reads and closes each device or communication handle.
A successful early-start run is a clue, not a complete repair. Determine whether workers still depend on resources created later, and whether shutdown and restart follow the same ownership rules.
### Fresh interpreters expose a different class of mistakes
Changing to `spawn` does not make arbitrary application structure correct. The child imports modules in a fresh interpreter. Device creation at module import can therefore run again, causing several workers to contend for a camera or connection. The usual main-module guard protects startup code only if resource creation is actually behind that boundary.
Keep worker functions importable and give them explicit, serialisable inputs. If a worker needs its own supported native context, initialise that context inside the worker according to the library's rules. A dedicated acquisition process can instead own the device and exchange bounded work items with compute workers. That design needs an explicit queue and shutdown policy, not merely a larger pool.
Fresh startup and data serialisation have costs. Prestarting workers can reduce latency but complicate lifecycle coordination. Forkserver can avoid inheriting an already busy application process, yet imported or preloaded code still deserves review for side effects. No start method supplies a universal guarantee for every SDK.
**Open engineering question:** which process owns each live native runtime in your robotics application, and can you reproduce worker startup and shutdown without opening the same hardware twice or inheriting an unsupported context?