From a3b73f51705cca64fc3997e6077181e24035a9d8 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 24 Jul 2013 15:08:24 -0400 Subject: [PATCH] use print_repl, honor silent, and evaluate user vars for #5; status messages for #4; still some weirdness for #10 --- jlkernel/handlers.jl | 56 +++++++++++++++++++++++++++++++++++++------- jlkernel/kernel.jl | 2 ++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/jlkernel/handlers.jl b/jlkernel/handlers.jl index 5efa4f90..14fb8f28 100644 --- a/jlkernel/handlers.jl +++ b/jlkernel/handlers.jl @@ -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)[ diff --git a/jlkernel/kernel.jl b/jlkernel/kernel.jl index 2e215806..0d762458 100644 --- a/jlkernel/kernel.jl +++ b/jlkernel/kernel.jl @@ -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