Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that open(::Function, ::Cmd) waits for termination #44078

Merged
merged 2 commits into from
Feb 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,25 @@ process failed, or if the process attempts to print anything to stdout.
"""
function open(f::Function, cmds::AbstractCmd, args...; kwargs...)
P = open(cmds, args...; kwargs...)
function waitkill(P::Process)
close(P)
# 0.1 seconds after we hope it dies (from closing stdio),
# we kill the process with SIGTERM (15)
local t = Timer(0.1) do t
process_running(P) && kill(P)
end
wait(P)
close(t)
end
ret = try
f(P)
catch
kill(P)
close(P)
waitkill(P)
rethrow()
end
close(P.in)
if !eof(P.out)
close(P.out)
waitkill(P)
throw(_UVError("open(do)", UV_EPIPE))
end
success(P) || pipeline_error(P)
Expand Down