Skip to content

Commit

Permalink
notebook command on Windows seems to need fix similar to #363; also, fix
Browse files Browse the repository at this point in the history
 #270 by doing explicit kill
  • Loading branch information
stevengj committed Oct 5, 2015
1 parent 33ec31a commit 715859a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
14 changes: 13 additions & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@ eprintln("Installing julia kernelspec $spec_name")
# remove these hacks when
# https://github.com/jupyter/notebook/issues/448 is closed and the fix
# is widely available -- just run `$jupyter kernelspec ...` then.
notebook = UTF8String[]
try
run(`$jupyter kernelspec install --replace --user $juliakspec`)
push!(notebook, jupyter, "notebook")
catch
@unix_only run(`$jupyter-kernelspec install --replace --user $juliakspec`)
@unix_only begin
run(`$jupyter-kernelspec install --replace --user $juliakspec`)
push!(notebook, jupyter * "-notebook")
end

# issue #363:
@windows_only begin
Expand All @@ -112,18 +117,25 @@ catch
if isfile(jk_path * "-script.py")
jk_path *= "-script.py"
end
jn_path = "$jupyter-notebook"
if isfile(jn_path * "-script.py")
jn_path *= "-script.py"
end
python = abspath(Conda.PYTHONDIR, "python.exe")
else
jk_path = readchomp(`where.exe $jupyter-kernelspec`)
jn_path = readchomp(`where.exe $jupyter-notebook`)
# jupyter-kernelspec should start with "#!/path/to/python":
python = chomp(open(readline, jk_path, "r"))[3:end]
end
run(`$python $jk_path install --replace --user $juliakspec`)
push!(notebook, python, jn_path)
end
end
open("deps.jl", "w") do f
print(f, """
const jupyter = "$(escape_string(jupyter))"
const notebook_cmd = ["$(join(map(escape_string, notebook), "\", \""))"]
const jupyter_vers = $(repr(jupyter_vers))
""")
end
Expand Down
20 changes: 14 additions & 6 deletions src/IJulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,22 @@ function waitloop()
end

export notebook
function notebook(jupyter=jupyter)
function notebook(; detached=false)
inited && error("IJulia is already running")
if basename(jupyter) == "jupyter"
# Remove the commit that added this when https://github.com/jupyter/notebook/issues/448 is closed
run(`$jupyter-notebook`)
else
run(`$jupyter notebook`)
p = spawn(detach(`$notebook_cmd`))

This comment has been minimized.

Copy link
@rened

rened Oct 15, 2015

Member

The change from using run to using detach means that there is no output from notebook_cmd visible in the REPL - one does not know if / what got started on which port.

This comment has been minimized.

Copy link
@stevengj

stevengj Oct 15, 2015

Author Member

Hmm, there should be a way to fix it...

This comment has been minimized.

Copy link
@rened

rened Oct 15, 2015

Member

Just brainstorming: perhaps a simple run for the non-detached version, as before, and @async readall for the detached version?

This comment has been minimized.

Copy link
@stevengj

stevengj Oct 15, 2015

Author Member

The problem with run is that it wasn't killing Jupyter reliably.

This comment has been minimized.

Copy link
@Keno

Keno Oct 15, 2015

Member

The problem is just that run and spawn have different defaults as to STDIO passthrough.

This comment has been minimized.

Copy link
@stevengj

stevengj Oct 15, 2015

Author Member

Is there a way to get stdio passthrough from spawn?

if !detached
try
wait(p)
catch e
if isa(e, InterruptException)
kill(p, 2) # SIGINT
else
kill(p) # SIGTERM
rethrow()
end
end
end
return p
end

end # IJulia

0 comments on commit 715859a

Please sign in to comment.