python-trio / python-trio/trio
run_process ignores thread context and spawns from threadpool
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.3k
- Forks
- 431
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Description
Hi,
run_process uses trio.to_thread.run_sync to spawn the subprocess; this means that the spawned process will inherit various context from a different thread. In my case this means it spawns in the wrong (network) namespace (see setns(2) - "reassociate thread with a namespace").
This might affect other things as well (pthreads(7) lists (among other things) capabilities and CPU affinity).
- the docs should mention this behavior
- it would be nice to have a flag to "spawn from current thread"
I'm also open to good suggestions how to work around this problem :)
(I might try prefixing the target command with ["/usr/bin/nsenter", "--target", threading.get_native_id(), "-n", "--"], or copy the trio run_process/open_process functions).
cheers,
Stefan
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the run_process and open_process entry points, including their use of trio.to_thread.run_sync, and review the linked namespace and pthread documentation. Confirm which thread context is inherited, then define the documented behavior and the scope of a current-thread spawning option or accepted workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100