##// END OF EJS Templates
use logging instead of `print >>` in pykernel
MinRK -
Show More
@@ -192,6 +192,7 b' class KernelApp(BaseIPythonApplication):'
192 shell_socket=self.shell_socket,
192 shell_socket=self.shell_socket,
193 iopub_socket=self.iopub_socket,
193 iopub_socket=self.iopub_socket,
194 stdin_socket=self.stdin_socket,
194 stdin_socket=self.stdin_socket,
195 log=self.log
195 )
196 )
196 self.kernel.record_ports(self.ports)
197 self.kernel.record_ports(self.ports)
197
198
@@ -60,6 +60,7 b' class Kernel(HasTraits):'
60 shell_socket = Instance('zmq.Socket')
60 shell_socket = Instance('zmq.Socket')
61 iopub_socket = Instance('zmq.Socket')
61 iopub_socket = Instance('zmq.Socket')
62 stdin_socket = Instance('zmq.Socket')
62 stdin_socket = Instance('zmq.Socket')
63 log = Instance('logging.Logger')
63
64
64 def __init__(self, **kwargs):
65 def __init__(self, **kwargs):
65 super(Kernel, self).__init__(**kwargs)
66 super(Kernel, self).__init__(**kwargs)
@@ -82,11 +83,10 b' class Kernel(HasTraits):'
82 ident,msg = self.session.recv(self.shell_socket,0)
83 ident,msg = self.session.recv(self.shell_socket,0)
83 assert ident is not None, "Missing message part."
84 assert ident is not None, "Missing message part."
84 omsg = Message(msg)
85 omsg = Message(msg)
85 print>>sys.__stdout__
86 self.log.debug(str(omsg))
86 print>>sys.__stdout__, omsg
87 handler = self.handlers.get(omsg.msg_type, None)
87 handler = self.handlers.get(omsg.msg_type, None)
88 if handler is None:
88 if handler is None:
89 print >> sys.__stderr__, "UNKNOWN MESSAGE TYPE:", omsg
89 self.log.error("UNKNOWN MESSAGE TYPE: %s"%omsg)
90 else:
90 else:
91 handler(ident, omsg)
91 handler(ident, omsg)
92
92
@@ -106,8 +106,7 b' class Kernel(HasTraits):'
106 try:
106 try:
107 code = parent[u'content'][u'code']
107 code = parent[u'content'][u'code']
108 except:
108 except:
109 print>>sys.__stderr__, "Got bad msg: "
109 self.log.error("Got bad msg: %s"%Message(parent))
110 print>>sys.__stderr__, Message(parent)
111 return
110 return
112 pyin_msg = self.session.send(self.iopub_socket, u'pyin',{u'code':code}, parent=parent)
111 pyin_msg = self.session.send(self.iopub_socket, u'pyin',{u'code':code}, parent=parent)
113
112
@@ -150,7 +149,7 b' class Kernel(HasTraits):'
150
149
151 # Send the reply.
150 # Send the reply.
152 reply_msg = self.session.send(self.shell_socket, u'execute_reply', reply_content, parent, ident=ident)
151 reply_msg = self.session.send(self.shell_socket, u'execute_reply', reply_content, parent, ident=ident)
153 print>>sys.__stdout__, Message(reply_msg)
152 self.log.debug(Message(reply_msg))
154 if reply_msg['content']['status'] == u'error':
153 if reply_msg['content']['status'] == u'error':
155 self._abort_queue()
154 self._abort_queue()
156
155
@@ -159,14 +158,14 b' class Kernel(HasTraits):'
159 'status' : 'ok'}
158 'status' : 'ok'}
160 completion_msg = self.session.send(self.shell_socket, 'complete_reply',
159 completion_msg = self.session.send(self.shell_socket, 'complete_reply',
161 matches, parent, ident)
160 matches, parent, ident)
162 print >> sys.__stdout__, completion_msg
161 self.log.debug(completion_msg)
163
162
164 def object_info_request(self, ident, parent):
163 def object_info_request(self, ident, parent):
165 context = parent['content']['oname'].split('.')
164 context = parent['content']['oname'].split('.')
166 object_info = self._object_info(context)
165 object_info = self._object_info(context)
167 msg = self.session.send(self.shell_socket, 'object_info_reply',
166 msg = self.session.send(self.shell_socket, 'object_info_reply',
168 object_info, parent, ident)
167 object_info, parent, ident)
169 print >> sys.__stdout__, msg
168 self.log.debug(msg)
170
169
171 def shutdown_request(self, ident, parent):
170 def shutdown_request(self, ident, parent):
172 content = dict(parent['content'])
171 content = dict(parent['content'])
@@ -174,7 +173,7 b' class Kernel(HasTraits):'
174 content, parent, ident)
173 content, parent, ident)
175 msg = self.session.send(self.iopub_socket, 'shutdown_reply',
174 msg = self.session.send(self.iopub_socket, 'shutdown_reply',
176 content, parent, ident)
175 content, parent, ident)
177 print >> sys.__stdout__, msg
176 self.log.debug(msg)
178 time.sleep(0.1)
177 time.sleep(0.1)
179 sys.exit(0)
178 sys.exit(0)
180
179
@@ -184,17 +183,17 b' class Kernel(HasTraits):'
184
183
185 def _abort_queue(self):
184 def _abort_queue(self):
186 while True:
185 while True:
187 ident,msg = self.session.recv(self.reply_socket, zmq.NOBLOCK)
186 ident,msg = self.session.recv(self.shell_socket, zmq.NOBLOCK)
188 if msg is None:
187 if msg is None:
188 # msg=None on EAGAIN
189 break
189 break
190 else:
190 else:
191 assert ident is not None, "Unexpected missing message part."
191 assert ident is not None, "Missing message part."
192 print>>sys.__stdout__, "Aborting:"
192 self.log.debug("Aborting: %s"%Message(msg))
193 print>>sys.__stdout__, Message(msg)
194 msg_type = msg['msg_type']
193 msg_type = msg['msg_type']
195 reply_type = msg_type.split('_')[0] + '_reply'
194 reply_type = msg_type.split('_')[0] + '_reply'
196 reply_msg = self.session.send(self.shell_socket, reply_type, {'status':'aborted'}, msg, ident=ident)
195 reply_msg = self.session.send(self.shell_socket, reply_type, {'status':'aborted'}, msg, ident=ident)
197 print>>sys.__stdout__, Message(reply_msg)
196 self.log.debug(Message(reply_msg))
198 # We need to wait a bit for requests to come in. This can probably
197 # We need to wait a bit for requests to come in. This can probably
199 # be set shorter for true asynchronous clients.
198 # be set shorter for true asynchronous clients.
200 time.sleep(0.1)
199 time.sleep(0.1)
@@ -213,8 +212,7 b' class Kernel(HasTraits):'
213 try:
212 try:
214 value = reply['content']['value']
213 value = reply['content']['value']
215 except:
214 except:
216 print>>sys.__stderr__, "Got bad raw_input reply: "
215 self.log.error("Got bad raw_input reply: %s"%Message(parent))
217 print>>sys.__stderr__, Message(parent)
218 value = ''
216 value = ''
219 return value
217 return value
220
218
General Comments 0
You need to be logged in to leave comments. Login now