Skip to content

Commit 50e12f3

Browse files
committed
Revert "Revert open(cmd) => Process change"
This reverts commit 8ffdfc2.
1 parent 4a2298d commit 50e12f3

File tree

7 files changed

+35
-28
lines changed

7 files changed

+35
-28
lines changed

base/loading.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function create_expr_cache(input::AbstractString, output::AbstractString)
333333
eval(Main, deserialize(STDIN))
334334
end
335335
"""
336-
io, pobj = open(detach(`$(julia_cmd())
336+
io = open(detach(`$(julia_cmd())
337337
--output-ji $output --output-incremental=yes
338338
--startup-file=no --history-file=no
339339
--eval $code_object`), "w", STDOUT)
@@ -360,10 +360,10 @@ function create_expr_cache(input::AbstractString, output::AbstractString)
360360
end)
361361
end
362362
close(io)
363-
wait(pobj)
364-
return pobj
363+
wait(io)
364+
return io
365365
catch
366-
kill(pobj)
366+
kill(io)
367367
close(io)
368368
rethrow()
369369
end

base/managers.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ function launch_on_machine(manager::SSHManager, machine, cnt, params, launched,
106106
cmd = `ssh -T -a -x -o ClearAllForwardings=yes -n $sshflags $host $(shell_escape(cmd))` # use ssh to remote launch
107107

108108
# launch
109-
io, pobj = open(detach(cmd), "r")
109+
pobj = open(detach(cmd), "r")
110110
wconfig = WorkerConfig()
111111

112-
wconfig.io = io
112+
wconfig.io = pobj.out
113113
wconfig.host = host
114114
wconfig.tunnel = params[:tunnel]
115115
wconfig.sshflags = sshflags
@@ -188,11 +188,11 @@ function launch(manager::LocalManager, params::Dict, launched::Array, c::Conditi
188188
exeflags = params[:exeflags]
189189

190190
for i in 1:manager.np
191-
io, pobj = open(detach(
191+
pobj = open(detach(
192192
setenv(`$(julia_cmd(exename)) $exeflags --bind-to $(LPROC.bind_addr) --worker`, dir=dir)), "r")
193193
wconfig = WorkerConfig()
194194
wconfig.process = pobj
195-
wconfig.io = io
195+
wconfig.io = pobj.out
196196
push!(launched, wconfig)
197197
end
198198

base/multi.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,8 @@ function launch_additional(np::Integer, cmd::Cmd)
12721272
addresses = cell(np)
12731273

12741274
for i in 1:np
1275-
io, pobj = open(detach(cmd), "r")
1276-
io_objs[i] = io
1275+
pobj = open(detach(cmd), "r")
1276+
io_objs[i] = pobj.out
12771277
end
12781278

12791279
for (i,io) in enumerate(io_objs)

base/process.jl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -465,46 +465,52 @@ eachline(cmd::AbstractCmd) = eachline(cmd, DevNull)
465465

466466
# return a Process object to read-to/write-from the pipeline
467467
function open(cmds::AbstractCmd, mode::AbstractString="r", other::AsyncStream=DevNull)
468-
if mode == "r"
468+
if mode == "r+" || mode == "w+"
469+
other === DevNull || throw(ArgumentError("no other stream for mode rw+"))
470+
in = Pipe()
471+
out = Pipe()
472+
processes = spawn(cmds, (in,out,STDERR))
473+
close(in.out)
474+
close(out.in)
475+
elseif mode == "r"
469476
in = other
470-
out = io = Pipe()
477+
out = Pipe()
471478
processes = spawn(cmds, (in,out,STDERR))
472479
close(out.in)
473480
elseif mode == "w"
474-
in = io = Pipe()
481+
in = Pipe()
475482
out = other
476483
processes = spawn(cmds, (in,out,STDERR))
477484
close(in.out)
478485
else
479486
throw(ArgumentError("mode must be \"r\" or \"w\", not \"$mode\""))
480487
end
481-
return (io, processes)
488+
return processes
482489
end
483490

484491
function open(f::Function, cmds::AbstractCmd, args...)
485-
io, P = open(cmds, args...)
492+
P = open(cmds, args...)
486493
ret = try
487-
f(io)
494+
f(P)
488495
catch
489496
kill(P)
490497
rethrow()
491498
finally
492-
close(io)
499+
close(P)
493500
end
494501
success(P) || pipeline_error(P)
495502
return ret
496503
end
497504

498505
# TODO: deprecate this
499506
function readandwrite(cmds::AbstractCmd)
500-
in = Pipe()
501-
out, processes = open(cmds, "r", in)
502-
(out, in, processes)
507+
processes = open(cmds, "r+")
508+
(processes.out, processes.in, processes)
503509
end
504510

505511
function readbytes(cmd::AbstractCmd, stdin::AsyncStream=DevNull)
506-
out, procs = open(cmd, "r", stdin)
507-
bytes = readbytes(out)
512+
procs = open(cmd, "r", stdin)
513+
bytes = readbytes(procs.out)
508514
!success(procs) && pipeline_error(procs)
509515
return bytes
510516
end

examples/clustermanager/simple/UnixDomainCM.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ function launch(manager::UnixDomainCM, params::Dict, launched::Array, c::Conditi
1212
sockname = tempname()
1313
try
1414
cmd = `$(params[:exename]) $(@__FILE__) udwrkr $sockname`
15-
io, pobj = open(cmd, "r")
15+
pobj = open(cmd, "r")
1616

1717
wconfig = WorkerConfig()
18-
wconfig.userdata = Dict(:sockname=>sockname, :io=>io, :process=>pobj)
18+
wconfig.userdata = Dict(:sockname=>sockname, :io=>pobj.out, :process=>pobj)
1919
push!(launched, wconfig)
2020
notify(c)
2121
catch e

test/examples.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ include(joinpath(dir, "queens.jl"))
4040
script = joinpath(dir, "clustermanager/simple/test_simple.jl")
4141
cmd = `$(joinpath(JULIA_HOME,Base.julia_exename())) $script`
4242

43-
(strm, proc) = open(cmd)
43+
proc = open(cmd)
44+
errors = readall(proc)
4445
wait(proc)
4546
if !success(proc) && ccall(:jl_running_on_valgrind,Cint,()) == 0
46-
println(readall(strm))
47+
println(errors)
4748
error("UnixDomainCM failed test, cmd : $cmd")
4849
end
4950
end

test/spawn.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ sleep(1)
231231
import Base.zzzInvalidIdentifier
232232
"""
233233
try
234-
(in,p) = open(`$exename -f`, "w")
234+
in = open(`$exename -f`, "w")
235235
write(in,cmd)
236236
close(in)
237-
wait(p)
237+
wait(in)
238238
catch
239239
error("IOStream redirect failed. Child stderr was \n$(readall(fname))\n")
240240
end

0 commit comments

Comments
 (0)