On Thursday, November 9, 2017 at 4:18:13 AM UTC-6, Edward K. Ream wrote:
>
>
> In production code, we might want to replace the "while True" loop in
> execute_one_cell with a callback that is called at idle time.
>
Here is working code, replacing execute_one_cell and call to same:
def execute_one_cell(code):
kc = getClient()
msgid = kc.execute(code=code, user_expressions={'a':'a'})
wait_time = time.time() + 3 # Wait no longer than 3 sec
n = 0
def jupyter_callback(timer, msgid=msgid, wait_time=wait_time):
try:
msg = kc.get_shell_msg(block=False)
response_id = getIn(msg, ['parent_header', 'msg_id'])
if response_id == msgid:
timer.stop()
val = getIn(msg, ['content', 'user_expressions', 'a', 'data'
, 'text/plain'])
g.trace('result:', val)
else:
g.trace('other message:', response_id)
except Empty:
if time.time() > wait_time:
timer.stop()
g.trace('timeout')
else:
g.trace('Empty')
timer = g.IdleTime(handler=jupyter_callback,delay=500)
if timer: timer.start()
execute_one_cell(code)
And here is a result:
jupyter_callback Empty
jupyter_callback result: 0.8414709848078965
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.