Skip to content

Commit

Permalink
use print_repl, honor silent, and evaluate user vars for #5; status m…
Browse files Browse the repository at this point in the history
…essages for #4; still some weirdness for #10
  • Loading branch information
stevengj committed Jul 24, 2013
1 parent 1bcb49d commit a3b73f5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
56 changes: 47 additions & 9 deletions jlkernel/handlers.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
function send_status(state::String)
send_ipython(publish,
Msg([ "status" ],
["msg_id" => uuid4(),
"username" => "jlkernel",
"session" => uuid4(),
"msg_type" => "status"],
[ "execution_state" => "starting" ]))
end

function execute_request(socket, msg)
user_variables = Dict() # TODO
user_expressions = Dict() # TODO
println("Executing ", msg.content["code"])
global _n
if !msg.content["silent"]
_n += 1
end

send_status("busy")

result = try
global _n += 1
println("Executing ", msg.content["code"])
eval(parse(msg.content["code"]))
catch
# FIXME
nothing
end
if msg.content["silent"] || ismatch(r";\s*$", msg.content["code"])
result = nothing
end

user_variables = Dict() # TODO
user_expressions = Dict() # TODO
try
for v in msg.content["user_variables"]
user_variables[v] = eval(parse(v))
end
for (v,ex) in msg.content["user_expressions"]
user_expressions[v] = eval(parse(ex))
end
catch
# ??
end

send_status("idle")

send_ipython(requests, msg_reply(msg, "execute_reply",
["status" => "ok",
"execution_count" => _n,
"payload" => [],
"user_variables" => user_variables,
"user_expressions" => user_expressions]))
send_ipython(publish,
msg_pub(msg, "pyout",
["execution_count" => _n,
"data" => [ "text/plain" => repr(result) ]
]))

if result != nothing
send_ipython(publish,
msg_pub(msg, "pyout",
["execution_count" => _n,
"data" => [ "text/plain" =>
sprint(repl_show, result) ]
]))
end
end

const handlers = (String=>Function)[
Expand Down
2 changes: 2 additions & 0 deletions jlkernel/kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ _n = 0
include("msg.jl")
include("handlers.jl")

send_status("starting")

# heartbeat (should eventually be forked in a separate thread & use zmq_device)
@async begin
while true
Expand Down

0 comments on commit a3b73f5

Please sign in to comment.