##// END OF EJS Templates
lazy-formatting logs in ipkernel...
MinRK -
Show More
@@ -142,7 +142,7 b' class Kernel(Configurable):'
142 self.handlers = {}
142 self.handlers = {}
143 for msg_type in msg_types:
143 for msg_type in msg_types:
144 self.handlers[msg_type] = getattr(self, msg_type)
144 self.handlers[msg_type] = getattr(self, msg_type)
145
145
146 control_msg_types = [ 'clear_request', 'abort_request' ]
146 control_msg_types = [ 'clear_request', 'abort_request' ]
147 self.control_handlers = {}
147 self.control_handlers = {}
148 for msg_type in control_msg_types:
148 for msg_type in control_msg_types:
@@ -151,7 +151,7 b' class Kernel(Configurable):'
151 def do_one_iteration(self):
151 def do_one_iteration(self):
152 """Do one iteration of the kernel's evaluation loop.
152 """Do one iteration of the kernel's evaluation loop.
153 """
153 """
154
154
155 try:
155 try:
156 ident,msg = self.session.recv(self.shell_socket, zmq.NOBLOCK)
156 ident,msg = self.session.recv(self.shell_socket, zmq.NOBLOCK)
157 except Exception:
157 except Exception:
@@ -170,13 +170,13 b' class Kernel(Configurable):'
170 # Print some info about this message and leave a '--->' marker, so it's
170 # Print some info about this message and leave a '--->' marker, so it's
171 # easier to trace visually the message chain when debugging. Each
171 # easier to trace visually the message chain when debugging. Each
172 # handler prints its message at the end.
172 # handler prints its message at the end.
173 self.log.debug('\n*** MESSAGE TYPE:'+str(msg_type)+'***')
173 self.log.debug('\n*** MESSAGE TYPE:%s***', msg_type)
174 self.log.debug(' Content: '+str(msg['content'])+'\n --->\n ')
174 self.log.debug(' Content: %s\n --->\n ', msg['content'])
175
175
176 # Find and call actual handler for message
176 # Find and call actual handler for message
177 handler = self.handlers.get(msg_type, None)
177 handler = self.handlers.get(msg_type, None)
178 if handler is None:
178 if handler is None:
179 self.log.error("UNKNOWN MESSAGE TYPE:" +str(msg))
179 self.log.error("UNKNOWN MESSAGE TYPE: %s", msg)
180 else:
180 else:
181 handler(ident, msg)
181 handler(ident, msg)
182
182
@@ -267,7 +267,7 b' class Kernel(Configurable):'
267 silent = content[u'silent']
267 silent = content[u'silent']
268 except:
268 except:
269 self.log.error("Got bad msg: ")
269 self.log.error("Got bad msg: ")
270 self.log.error(str(Message(parent)))
270 self.log.error("%s", parent)
271 return
271 return
272
272
273 shell = self.shell # we'll need this a lot here
273 shell = self.shell # we'll need this a lot here
@@ -365,7 +365,7 b' class Kernel(Configurable):'
365 reply_content = json_clean(reply_content)
365 reply_content = json_clean(reply_content)
366 reply_msg = self.session.send(self.shell_socket, u'execute_reply',
366 reply_msg = self.session.send(self.shell_socket, u'execute_reply',
367 reply_content, parent, ident=ident)
367 reply_content, parent, ident=ident)
368 self.log.debug(str(reply_msg))
368 self.log.debug("%s", reply_msg)
369
369
370 if reply_msg['content']['status'] == u'error':
370 if reply_msg['content']['status'] == u'error':
371 self._abort_queue()
371 self._abort_queue()
@@ -383,7 +383,7 b' class Kernel(Configurable):'
383 matches = json_clean(matches)
383 matches = json_clean(matches)
384 completion_msg = self.session.send(self.shell_socket, 'complete_reply',
384 completion_msg = self.session.send(self.shell_socket, 'complete_reply',
385 matches, parent, ident)
385 matches, parent, ident)
386 self.log.debug(str(completion_msg))
386 self.log.debug("%s", completion_msg)
387
387
388 def object_info_request(self, ident, parent):
388 def object_info_request(self, ident, parent):
389 content = parent['content']
389 content = parent['content']
@@ -394,7 +394,7 b' class Kernel(Configurable):'
394 oinfo = json_clean(object_info)
394 oinfo = json_clean(object_info)
395 msg = self.session.send(self.shell_socket, 'object_info_reply',
395 msg = self.session.send(self.shell_socket, 'object_info_reply',
396 oinfo, parent, ident)
396 oinfo, parent, ident)
397 self.log.debug(msg)
397 self.log.debug("%s", msg)
398
398
399 def history_request(self, ident, parent):
399 def history_request(self, ident, parent):
400 # We need to pull these out, as passing **kwargs doesn't work with
400 # We need to pull these out, as passing **kwargs doesn't work with
@@ -435,7 +435,7 b' class Kernel(Configurable):'
435 content = {}
435 content = {}
436 msg = self.session.send(self.shell_socket, 'connect_reply',
436 msg = self.session.send(self.shell_socket, 'connect_reply',
437 content, parent, ident)
437 content, parent, ident)
438 self.log.debug(msg)
438 self.log.debug("%s", msg)
439
439
440 def shutdown_request(self, ident, parent):
440 def shutdown_request(self, ident, parent):
441 self.shell.exit_now = True
441 self.shell.exit_now = True
@@ -456,7 +456,7 b' class Kernel(Configurable):'
456 msg_id = parent['header']['msg_id']
456 msg_id = parent['header']['msg_id']
457 # bound = parent['header'].get('bound', False)
457 # bound = parent['header'].get('bound', False)
458 except:
458 except:
459 self.log.error("Got bad msg: %s"%parent, exc_info=True)
459 self.log.error("Got bad msg: %s", parent, exc_info=True)
460 return
460 return
461 # pyin_msg = self.session.msg(u'pyin',{u'code':code}, parent=parent)
461 # pyin_msg = self.session.msg(u'pyin',{u'code':code}, parent=parent)
462 # self.iopub_stream.send(pyin_msg)
462 # self.iopub_stream.send(pyin_msg)
@@ -520,7 +520,7 b' class Kernel(Configurable):'
520 # flush i/o
520 # flush i/o
521 sys.stdout.flush()
521 sys.stdout.flush()
522 sys.stderr.flush()
522 sys.stderr.flush()
523
523
524 reply_msg = self.session.send(stream, u'apply_reply', reply_content,
524 reply_msg = self.session.send(stream, u'apply_reply', reply_content,
525 parent=parent, ident=ident,buffers=result_buf, subheader=sub)
525 parent=parent, ident=ident,buffers=result_buf, subheader=sub)
526
526
@@ -540,7 +540,7 b' class Kernel(Configurable):'
540 return
540 return
541
541
542 self.log.info("Aborting:")
542 self.log.info("Aborting:")
543 self.log.info(str(msg))
543 self.log.info("%s", msg)
544 msg_type = msg['header']['msg_type']
544 msg_type = msg['header']['msg_type']
545 reply_type = msg_type.split('_')[0] + '_reply'
545 reply_type = msg_type.split('_')[0] + '_reply'
546 # reply_msg = self.session.msg(reply_type, {'status' : 'aborted'}, msg)
546 # reply_msg = self.session.msg(reply_type, {'status' : 'aborted'}, msg)
@@ -548,7 +548,7 b' class Kernel(Configurable):'
548 # self.reply_socket.send_json(reply_msg)
548 # self.reply_socket.send_json(reply_msg)
549 reply_msg = self.session.send(stream, reply_type,
549 reply_msg = self.session.send(stream, reply_type,
550 content={'status' : 'aborted'}, parent=msg, ident=idents)
550 content={'status' : 'aborted'}, parent=msg, ident=idents)
551 self.log.debug(str(reply_msg))
551 self.log.debug("%s", reply_msg)
552 # We need to wait a bit for requests to come in. This can probably
552 # We need to wait a bit for requests to come in. This can probably
553 # be set shorter for true asynchronous clients.
553 # be set shorter for true asynchronous clients.
554 time.sleep(0.05)
554 time.sleep(0.05)
@@ -566,7 +566,7 b' class Kernel(Configurable):'
566 content = dict(status='ok')
566 content = dict(status='ok')
567 reply_msg = self.session.send(stream, 'abort_reply', content=content,
567 reply_msg = self.session.send(stream, 'abort_reply', content=content,
568 parent=parent, ident=ident)
568 parent=parent, ident=ident)
569 self.log.debug(str(reply_msg))
569 self.log.debug("%s", reply_msg)
570
570
571 def clear_request(self, stream, idents, parent):
571 def clear_request(self, stream, idents, parent):
572 """Clear our namespace."""
572 """Clear our namespace."""
@@ -593,12 +593,12 b' class Kernel(Configurable):'
593 assert ident is not None, \
593 assert ident is not None, \
594 "Unexpected missing message part."
594 "Unexpected missing message part."
595
595
596 self.log.debug("Aborting:\n"+str(Message(msg)))
596 self.log.debug("Aborting:\n%s", msg)
597 msg_type = msg['header']['msg_type']
597 msg_type = msg['header']['msg_type']
598 reply_type = msg_type.split('_')[0] + '_reply'
598 reply_type = msg_type.split('_')[0] + '_reply'
599 reply_msg = self.session.send(self.shell_socket, reply_type,
599 reply_msg = self.session.send(self.shell_socket, reply_type,
600 {'status' : 'aborted'}, msg, ident=ident)
600 {'status' : 'aborted'}, msg, ident=ident)
601 self.log.debug(reply_msg)
601 self.log.debug("%s", reply_msg)
602 # We need to wait a bit for requests to come in. This can probably
602 # We need to wait a bit for requests to come in. This can probably
603 # be set shorter for true asynchronous clients.
603 # be set shorter for true asynchronous clients.
604 time.sleep(0.1)
604 time.sleep(0.1)
@@ -631,7 +631,7 b' class Kernel(Configurable):'
631 value = reply['content']['value']
631 value = reply['content']['value']
632 except:
632 except:
633 self.log.error("Got bad raw_input reply: ")
633 self.log.error("Got bad raw_input reply: ")
634 self.log.error(str(Message(parent)))
634 self.log.error("%s", parent)
635 value = ''
635 value = ''
636 if value == '\x04':
636 if value == '\x04':
637 # EOF
637 # EOF
@@ -688,7 +688,7 b' class Kernel(Configurable):'
688 if self._shutdown_message is not None:
688 if self._shutdown_message is not None:
689 self.session.send(self.shell_socket, self._shutdown_message)
689 self.session.send(self.shell_socket, self._shutdown_message)
690 self.session.send(self.iopub_socket, self._shutdown_message)
690 self.session.send(self.iopub_socket, self._shutdown_message)
691 self.log.debug(str(self._shutdown_message))
691 self.log.debug("%s", self._shutdown_message)
692 # A very short sleep to give zmq time to flush its message buffers
692 # A very short sleep to give zmq time to flush its message buffers
693 # before Python truly shuts down.
693 # before Python truly shuts down.
694 time.sleep(0.01)
694 time.sleep(0.01)
General Comments 0
You need to be logged in to leave comments. Login now