Example #1
0
def _BlockOnRawInputReplyPepper():
  """Blocks until a message in the stdin channel is recieved.

  For use while running the PNaCl/Pepper kernel.

  Returns:
    The value of the message, which is assumed to be of type raw_input_reply
  """

  # pylint: disable=g-import-not-at-top,protected-access,bare-except
  from pyppapi import nacl_instance
  raw_reply = nacl_instance.wait_for_message()
  try:
    reply = json.loads(raw_reply['json'])
    value = reply['content']['value']
  except:
    # handle bad raw_input reply
    value = raw_reply
  return value
Example #2
0
def deal_message(msg):
    channel = msg['stream']
    content = json.loads(msg['json'])

    queues = {'shell': shell_input, 'stdin': stdin_input}
    queue = queues[channel]

    queue.put(content)


def send_message(stream, msg):
    nacl_instance.send_raw_object({'stream': stream, 'json': json.dumps(msg)})


while 1:
    msg = nacl_instance.wait_for_message(timeout=1, sleeptime=10000)
    try:
        deal_message(msg)
    except:
        pass

    output_streams = [(stdin_output, 'stdin'), (shell_output, 'shell'),
                      (iopub_output, 'iopub')]
    for msg_queue, stream in output_streams:
        msg = None
        try:
            msg = msg_queue.get_nowait()
            send_message(stream, msg)
        except Queue.Empty:
            pass
Example #3
0
import matplotlib
import matplotlib.cbook
""")

execution_count = 1

shell = PepperKernel().shell

# Special message to indicate the NaCl kernel is ready.
sendMessage('iopub', 'status', content={'execution_state': 'nacl_ready'})

while 1:
  sendMessage('iopub', 'status', content={'execution_state': 'idle'})
  msg = None
  while msg is None:
    msg = nacl_instance.wait_for_message()
  msg = json.loads(msg['json'])
  sendMessage('iopub', 'status', content={'execution_state': 'busy'})

  if not 'header' in msg:
    continue
  request_header = msg['header']
  if not 'msg_type' in request_header:
    continue
  msg_type = request_header['msg_type']
  if msg_type == 'execute_request':
    try:
      content = msg[u'content']
      code = content[u'code']
      silent = content[u'silent']
      store_history = content.get(u'store_history', not silent)
Example #4
0
    # If we don't get something that we can convert to an integer, at
    # least attempt the completion guessing the cursor is at the end of
    # the text, if there's any, and otherwise of the line
    cpos = len(c['text'])
    if cpos==0:
      cpos = len(c['line'])
  return shell.complete(c['text'], c['line'], cpos)

# Special message to indicate the NaCl kernel is ready.
sendMessage('iopub', 'status', content={'execution_state': 'nacl_ready'})

while 1:
  sendMessage('iopub', 'status', content={'execution_state': 'idle'})
  msg = None
  while msg is None:
    msg = nacl_instance.wait_for_message()
  msg = json.loads(msg['json'])
  sendMessage('iopub', 'status', content={'execution_state': 'busy'})

  if not 'header' in msg:
    continue
  request_header = msg['header']
  if not 'msg_type' in request_header:
    continue
  msg_type = request_header['msg_type']
  if msg_type == 'execute_request':
    try:
      content = msg[u'content']
      code = content[u'code']
      silent = content[u'silent']
      store_history = content.get(u'store_history', not silent)