Add deliver_cancel
parameter and start
support to run_process
#673
Labels
enhancement
New feature or request
Things to check first
Feature description
Trio
deliver_cancel
parameter andnursery.start
support inrun_process
process = await nursery.start(run_process, ...)
instead ofopen_process
.open_process
tolowlevel
Process.aclose
Use case
process = await nursery.start(trio.run_process, ...)
actually enforces structured concurrency—you can't accidentally leave an orphan process1open_process
does not enforce structured concurrency, hence it should be inlowlevel
. while you can make it enforce structured concurrency by doingasync with await trio.lowlevel.open_process() as process
,process = await trio.lowlevel.open_process()
by itself does not use structured concurrency and is basicallyfork()
without afinally: wait(pid)
to follow it. hence i lean toward agreeing thatopen_process
should be inlowlevel
.i'd like to propose doing (1) and (2) in AnyIO: adding
deliver_cancel
support andTaskGroup.start
support torun_process
. i actually ended implementing this some months ago in a downstream AnyIO application at work, because upon cancellation we needed to send the child a gentleSIGINT
first instead of reaching straight forSIGKILL
and causing data loss. i'd be happy to move that implementation upstream if it seems reasonable.if proposals (1) and (2) are accepted, AnyIO could also consider doing (3) and/or (4). they also make sense to me, as mentioned above—put
open_process
inlowlevel
so users think twice before shooting themselves in the foot with the gun-that-orphans-processes.thoughts?
Footnotes
except if the parent gets
SIGKILL
/TerminateProcess
and can't run anyexcept/finally/__exit__/__aexit__/atexit
code. ↩The text was updated successfully, but these errors were encountered: