run_process ignores thread context and spawns from threadpool
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)](https://manpages.debian.org/testing/manpages-dev/setns.2.en.html) - "reassociate thread with a namespace").
This might affect other things as well ([pthreads(7)](https://manpages.debian.org/testing/manpages/pthreads.7.en.html) lists (among other things) capabilities and CPU affinity).
1. the docs should mention this behavior
2. 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
1 条评论