diff --git a/base/loading.jl b/base/loading.jl index 67b3882017865..6460bc3fa8b14 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -296,7 +296,7 @@ function create_expr_cache(input::AbstractString, output::AbstractString) eval(Main, deserialize(STDIN)) end """ - io, pobj = open(detach(`$(julia_cmd()) + io = open(detach(`$(julia_cmd()) --output-ji $output --output-incremental=yes --startup-file=no --history-file=no --eval $code_object`), "w", STDOUT) @@ -321,9 +321,9 @@ function create_expr_cache(input::AbstractString, output::AbstractString) delete!(task_local_storage(), :SOURCE_PATH) end) end - close(io) - wait(pobj) - return pobj + close(io.in) + wait(io) + return io end compilecache(mod::Symbol) = compilecache(string(mod)) diff --git a/base/managers.jl b/base/managers.jl index 5102eecb70097..bddca3f68cf85 100644 --- a/base/managers.jl +++ b/base/managers.jl @@ -106,10 +106,10 @@ function launch_on_machine(manager::SSHManager, machine, cnt, params, launched, cmd = `ssh -T -a -x -o ClearAllForwardings=yes -n $sshflags $host $(shell_escape(cmd))` # use ssh to remote launch # launch - io, pobj = open(detach(cmd), "r") + pobj = open(detach(cmd), "r") wconfig = WorkerConfig() - wconfig.io = io + wconfig.io = pobj.out wconfig.host = host wconfig.tunnel = params[:tunnel] wconfig.sshflags = sshflags @@ -188,11 +188,11 @@ function launch(manager::LocalManager, params::Dict, launched::Array, c::Conditi exeflags = params[:exeflags] for i in 1:manager.np - io, pobj = open(detach( + pobj = open(detach( setenv(`$(julia_cmd(exename)) $exeflags --bind-to $(LPROC.bind_addr) --worker`, dir=dir)), "r") wconfig = WorkerConfig() wconfig.process = pobj - wconfig.io = io + wconfig.io = pobj.out push!(launched, wconfig) end diff --git a/base/multi.jl b/base/multi.jl index 8064d7b56a4db..530029d2d3ae3 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -1269,8 +1269,8 @@ function launch_additional(np::Integer, cmd::Cmd) addresses = cell(np) for i in 1:np - io, pobj = open(detach(cmd), "r") - io_objs[i] = io + pobj = open(detach(cmd), "r") + io_objs[i] = pobj.out end for (i,io) in enumerate(io_objs) diff --git a/base/process.jl b/base/process.jl index 879e4288bf356..56f41390d7655 100644 --- a/base/process.jl +++ b/base/process.jl @@ -465,31 +465,38 @@ eachline(cmd::AbstractCmd) = eachline(cmd, DevNull) # return a Process object to read-to/write-from the pipeline function open(cmds::AbstractCmd, mode::AbstractString="r", other::AsyncStream=DevNull) - if mode == "r" + if mode == "r+" || mode == "w+" + other === DevNull || throw(ArgumentError("no other stream for mode rw+")) + in = Pipe() + out = Pipe() + processes = spawn(cmds, (in,out,STDERR)) + close(in.out) + close(out.in) + elseif mode == "r" in = other - out = io = Pipe() + out = Pipe() processes = spawn(cmds, (in,out,STDERR)) close(out.in) elseif mode == "w" - in = io = Pipe() + in = Pipe() out = other processes = spawn(cmds, (in,out,STDERR)) close(in.out) else throw(ArgumentError("mode must be \"r\" or \"w\", not \"$mode\"")) end - return (io, processes) + return processes end function open(f::Function, cmds::AbstractCmd, args...) - io, P = open(cmds, args...) + P = open(cmds, args...) ret = try - f(io) + f(P) catch kill(P) rethrow() finally - close(io) + close(P) end success(P) || pipeline_error(P) return ret @@ -497,14 +504,13 @@ end # TODO: deprecate this function readandwrite(cmds::AbstractCmd) - in = Pipe() - out, processes = open(cmds, "r", in) - (out, in, processes) + processes = open(cmds, "r+") + (processes.out, processes.in, processes) end function readbytes(cmd::AbstractCmd, stdin::AsyncStream=DevNull) - out, procs = open(cmd, "r", stdin) - bytes = readbytes(out) + procs = open(cmd, "r", stdin) + bytes = readbytes(procs.out) !success(procs) && pipeline_error(procs) return bytes end diff --git a/examples/clustermanager/simple/UnixDomainCM.jl b/examples/clustermanager/simple/UnixDomainCM.jl index 2c356cee3847d..f5d5339c9dfb0 100644 --- a/examples/clustermanager/simple/UnixDomainCM.jl +++ b/examples/clustermanager/simple/UnixDomainCM.jl @@ -12,10 +12,10 @@ function launch(manager::UnixDomainCM, params::Dict, launched::Array, c::Conditi sockname = tempname() try cmd = `$(params[:exename]) $(@__FILE__) udwrkr $sockname` - io, pobj = open(cmd, "r") + pobj = open(cmd, "r") wconfig = WorkerConfig() - wconfig.userdata = Dict(:sockname=>sockname, :io=>io, :process=>pobj) + wconfig.userdata = Dict(:sockname=>sockname, :io=>pobj.out, :process=>pobj) push!(launched, wconfig) notify(c) catch e diff --git a/test/examples.jl b/test/examples.jl index fb64ce6b418ad..284ad096ca8a4 100644 --- a/test/examples.jl +++ b/test/examples.jl @@ -40,10 +40,11 @@ include(joinpath(dir, "queens.jl")) script = joinpath(dir, "clustermanager/simple/test_simple.jl") cmd = `$(joinpath(JULIA_HOME,Base.julia_exename())) $script` - (strm, proc) = open(cmd) + proc = open(cmd) + errors = readall(proc) wait(proc) if !success(proc) && ccall(:jl_running_on_valgrind,Cint,()) == 0 - println(readall(strm)) + println(errors) error("UnixDomainCM failed test, cmd : $cmd") end end diff --git a/test/spawn.jl b/test/spawn.jl index cc33cb0811010..06cb63016ef68 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -231,10 +231,10 @@ sleep(1) import Base.zzzInvalidIdentifier """ try - (in,p) = open(`$exename -f`, "w") + in = open(`$exename -f`, "w") write(in,cmd) close(in) - wait(p) + wait(in) catch error("IOStream redirect failed. Child stderr was \n$(readall(fname))\n") end