On Tuesday, November 7, 2017 at 10:32:25 AM UTC-6, Edward K. Ream wrote:
>
> On Tue, Nov 7, 2017 at 10:24 AM, Terry Brown <[email protected]>
> wrote:
>
>> it seems like non-blocking would be very valuable
>> with computations on the Jupyter end that take a long time.
>
>
> jupyter issue #242 <https://github.com/jupyter/help/issues/242> asks
> for help on exactly this topic.
>
I have just closed this issue. The short answer is that subclasses can
override class-level traitlets at the class level.
Here is a tested Leo script. It shows how to define several classes needed
to create a non-blocking client. The
NonBlockingKernelClient and NonBlockingKernelClient classes are incomplete, but
the code goes through the init
logic without crashing:
import jupyter_clientfrom traitlets import DottedObjectName, Typetry:
from queue import Queue, Empty # Python 3except ImportError:
from Queue import Queue, Empty # Python 2
code = '''\import matha = math.sin(1)'''def getIn(r, path):
for p in path:
r = r.get(p, {})
return r
class NonBlockingChannel (jupyter_client.channelsabc.ChannelABC):
def __init__(self, socket, session, ioloop):
self.socket = socket
self.session = session
self.ioloop = ioloop
def get_msg(self, block=True, timeout=None):
return {} # Not ready yet.
def is_alive(self):
return True
def start(self):
self._is_alive = True
def stop(self):
self._is_alive = False
def send(self, msg):
pass # Not ready yet.
class NonBlockingKernelClient (jupyter_client.KernelClient):
shell_channel_class = NonBlockingChannel # Type(NonBlockingChannel)
iopub_channel_class = NonBlockingChannel # Type(NonBlockingChannel)
stdin_channel_class = NonBlockingChannel # Type(NonBlockingChannel)
hb_channel_class = jupyter_client.channels.HBChannel # Type(HBChannelABC)
def wait_for_ready(self, timeout=None):
pass # Not ready yet.
class NonBlockingManager (jupyter_client.manager.KernelManager):
client_class = DottedObjectName('jupyter_client.KernelClient')
client_factory = NonBlockingKernelClient #
Type(klass='NonBlockingKernelClient')
def start_new_non_blocking_kernel(startup_timeout=60, kernel_name='python',
**kwargs):
# Similar to manager.start_new_kernel, but instantiates NonBlockingManager
class
km = NonBlockingManager(kernel_name=kernel_name)
km.start_kernel(**kwargs)
kc = km.client()
kc.start_channels()
try:
kc.wait_for_ready(timeout=startup_timeout)
except RuntimeError:
kc.stop_channels()
km.shutdown_kernel()
raise
return km, kc
km, kc = start_new_non_blocking_kernel()
kc.execute(code=code, user_expressions={'a':'a'})
msg = kc.get_shell_msg()print(getIn(msg, ['content', 'user_expressions', 'a',
'data', 'text/plain']))
This is good enough for now. We can use the simpler, blocking, code during
development.
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.