On Tuesday, November 7, 2017 at 5:07:32 AM UTC-6, vitalije wrote:
Briefly, I looked at the code and I have just realized that my example
> could be even simpler. Blocking client expects reply=True keyword argument,
> when sending requests for computation and if it is found, than it waits for
> the reply and returns it.
>
> Look in jupyter_client.blocking.client module. There you can see what is
> changed in blocking class.
>
It's mysterious to me how to subclass any of the jupyter classes.
Here is another approach. Starting from your script, it caches the
kernel. The second time it is run, it successfully uses the previously
created kernel.
t1 = time.clock()
d = g.app.permanentScriptDict
kern = d.get('kernel')
print('kernel...', kern)
if not kern:
# from run_kernel, which can't be used directly
km = jupyter_client.KernelManager(kernel_name='python')
km.start_kernel()
kc = km.client()
kc.start_channels()
kc.wait_for_ready(timeout=60)
d['kernel'] = kern = kc
kern.execute(code=code, user_expressions={'a':'a'})
msg = kern.get_shell_msg()
resultDict = getIn(msg, ['content', 'user_expressions', 'a'])
result = getIn(msg, ['content', 'user_expressions', 'a', 'data',
'text/plain'])
print('%2.4f sec' % (time.clock()-t1))
The first time this is executed, the output is:
kernel... None
1.0270 sec
The second time, there is no need to create the kernel again:
kernel... <jupyter_client.blocking.client.BlockingKernelClient object at
0x0ADA3210>
0.0181 sec
In short, using a blocking client seems fast enough.
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.