##// END OF EJS Templates
logging implemented kernel's messages
Omar Andres Zapata Mesa -
Show More
@@ -1,3 +1,4 b''
1 import logging
1 2 import sys
2 3 import time
3 4 from cStringIO import StringIO
@@ -15,7 +16,7 b' class OutStream(object):'
15 16
16 17 # The time interval between automatic flushes, in seconds.
17 18 flush_interval = 0.05
18
19 _logger = logging.getLogger()
19 20 def __init__(self, session, pub_socket, name):
20 21 self.session = session
21 22 self.pub_socket = pub_socket
@@ -39,7 +40,7 b' class OutStream(object):'
39 40 content = {u'name':self.name, u'data':data}
40 41 msg = self.session.msg(u'stream', content=content,
41 42 parent=self.parent_header)
42 io.raw_print(msg)
43 self._logger.debug(msg)
43 44 self.pub_socket.send_json(msg)
44 45
45 46 self._buffer.close()
@@ -21,7 +21,7 b' import atexit'
21 21 import sys
22 22 import time
23 23 import traceback
24
24 import logging
25 25 # System library imports.
26 26 import zmq
27 27
@@ -79,7 +79,10 b' class Kernel(Configurable):'
79 79 # This is a dict of port number that the kernel is listening on. It is set
80 80 # by record_ports and used by connect_request.
81 81 _recorded_ports = None
82
82
83
84 _logger = logging.getLogger()
85
83 86 def __init__(self, **kwargs):
84 87 super(Kernel, self).__init__(**kwargs)
85 88
@@ -122,21 +125,20 b' class Kernel(Configurable):'
122 125 # easier to trace visually the message chain when debugging. Each
123 126 # handler prints its message at the end.
124 127 # Eventually we'll move these from stdout to a logger.
125 io.raw_print('\n*** MESSAGE TYPE:', msg['msg_type'], '***')
126 io.raw_print(' Content: ', msg['content'],
127 '\n --->\n ', sep='', end='')
128 self._logger.debug('\n*** MESSAGE TYPE:'+str(msg['msg_type'])+'***')
129 self._logger.debug(' Content: '+str(msg['content'])+'\n --->\n ')
128 130
129 131 # Find and call actual handler for message
130 132 handler = self.handlers.get(msg['msg_type'], None)
131 133 if handler is None:
132 io.raw_print_err("UNKNOWN MESSAGE TYPE:", msg)
134 self._logger.error("UNKNOWN MESSAGE TYPE:" +str(msg))
133 135 else:
134 136 handler(ident, msg)
135 137
136 138 # Check whether we should exit, in case the incoming message set the
137 139 # exit flag on
138 140 if self.shell.exit_now:
139 io.raw_print('\nExiting IPython kernel...')
141 self._logger.debug('\nExiting IPython kernel...')
140 142 # We do a normal, clean exit, which allows any actions registered
141 143 # via atexit (such as history saving) to take place.
142 144 sys.exit(0)
@@ -186,8 +188,8 b' class Kernel(Configurable):'
186 188 code = content[u'code']
187 189 silent = content[u'silent']
188 190 except:
189 io.raw_print_err("Got bad msg: ")
190 io.raw_print_err(Message(parent))
191 self._logger.error("Got bad msg: ")
192 self._logger.error(str(Message(parent)))
191 193 return
192 194
193 195 shell = self.shell # we'll need this a lot here
@@ -265,7 +267,7 b' class Kernel(Configurable):'
265 267
266 268 # Send the reply.
267 269 reply_msg = self.session.msg(u'execute_reply', reply_content, parent)
268 io.raw_print(reply_msg)
270 self._logger.debug(str(reply_msg))
269 271
270 272 # Flush output before sending the reply.
271 273 sys.stdout.flush()
@@ -295,7 +297,7 b' class Kernel(Configurable):'
295 297 'status' : 'ok'}
296 298 completion_msg = self.session.send(self.reply_socket, 'complete_reply',
297 299 matches, parent, ident)
298 io.raw_print(completion_msg)
300 self._logger.debug(str(completion_msg))
299 301
300 302 def object_info_request(self, ident, parent):
301 303 object_info = self.shell.object_inspect(parent['content']['oname'])
@@ -303,7 +305,7 b' class Kernel(Configurable):'
303 305 oinfo = json_clean(object_info)
304 306 msg = self.session.send(self.reply_socket, 'object_info_reply',
305 307 oinfo, parent, ident)
306 io.raw_print(msg)
308 self._logger.debug(msg)
307 309
308 310 def history_request(self, ident, parent):
309 311 output = parent['content']['output']
@@ -313,7 +315,7 b' class Kernel(Configurable):'
313 315 content = {'history' : hist}
314 316 msg = self.session.send(self.reply_socket, 'history_reply',
315 317 content, parent, ident)
316 io.raw_print(msg)
318 self._logger.debug(str(msg))
317 319
318 320 def connect_request(self, ident, parent):
319 321 if self._recorded_ports is not None:
@@ -322,7 +324,7 b' class Kernel(Configurable):'
322 324 content = {}
323 325 msg = self.session.send(self.reply_socket, 'connect_reply',
324 326 content, parent, ident)
325 io.raw_print(msg)
327 self._logger.debug(msg)
326 328
327 329 def shutdown_request(self, ident, parent):
328 330 self.shell.exit_now = True
@@ -344,11 +346,11 b' class Kernel(Configurable):'
344 346 assert self.reply_socket.rcvmore(), \
345 347 "Unexpected missing message part."
346 348 msg = self.reply_socket.recv_json()
347 io.raw_print("Aborting:\n", Message(msg))
349 self._logger.debug("Aborting:\n"+str(Message(msg)))
348 350 msg_type = msg['msg_type']
349 351 reply_type = msg_type.split('_')[0] + '_reply'
350 352 reply_msg = self.session.msg(reply_type, {'status' : 'aborted'}, msg)
351 io.raw_print(reply_msg)
353 self._logger.debug(reply_msg)
352 354 self.reply_socket.send(ident,zmq.SNDMORE)
353 355 self.reply_socket.send_json(reply_msg)
354 356 # We need to wait a bit for requests to come in. This can probably
@@ -370,8 +372,8 b' class Kernel(Configurable):'
370 372 try:
371 373 value = reply['content']['value']
372 374 except:
373 io.raw_print_err("Got bad raw_input reply: ")
374 io.raw_print_err(Message(parent))
375 self._logger.error("Got bad raw_input reply: ")
376 self._logger.error(str(Message(parent)))
375 377 value = ''
376 378 return value
377 379
@@ -425,7 +427,7 b' class Kernel(Configurable):'
425 427 if self._shutdown_message is not None:
426 428 self.reply_socket.send_json(self._shutdown_message)
427 429 self.pub_socket.send_json(self._shutdown_message)
428 io.raw_print(self._shutdown_message)
430 self._logger.debug(str(self._shutdown_message))
429 431 # A very short sleep to give zmq time to flush its message buffers
430 432 # before Python truly shuts down.
431 433 time.sleep(0.01)
@@ -23,6 +23,7 b' import signal'
23 23 import sys
24 24 from threading import Thread
25 25 import time
26 import logging
26 27
27 28 # System library imports.
28 29 import zmq
General Comments 0
You need to be logged in to leave comments. Login now