@@ -121,6 +121,8 @@ def _ident_default(self):
121121 # deprecated:
122122 'apply_request' ,
123123 ]
124+ # add deprecated ipyparallel control messages
125+ control_msg_types = msg_types + ['clear_request' , 'abort_request' ]
124126
125127 def __init__ (self , ** kwargs ):
126128 super (Kernel , self ).__init__ (** kwargs )
@@ -130,9 +132,8 @@ def __init__(self, **kwargs):
130132 for msg_type in self .msg_types :
131133 self .shell_handlers [msg_type ] = getattr (self , msg_type )
132134
133- control_msg_types = self .msg_types + [ 'clear_request' , 'abort_request' ]
134135 self .control_handlers = {}
135- for msg_type in control_msg_types :
136+ for msg_type in self . control_msg_types :
136137 self .control_handlers [msg_type ] = getattr (self , msg_type )
137138
138139
@@ -167,6 +168,25 @@ def dispatch_control(self, msg):
167168 sys .stderr .flush ()
168169 self ._publish_status (u'idle' )
169170
171+ def should_handle (self , stream , msg , idents ):
172+ """Check whether a shell-channel message should be handled
173+
174+ Allows subclasses to prevent handling of certain messages (e.g. aborted requests).
175+ """
176+ msg_id = msg ['header' ]['msg_id' ]
177+ if msg_id in self .aborted :
178+ msg_type = msg ['header' ]['msg_type' ]
179+ # is it safe to assume a msg_id will not be resubmitted?
180+ self .aborted .remove (msg_id )
181+ reply_type = msg_type .split ('_' )[0 ] + '_reply'
182+ status = {'status' : 'aborted' }
183+ md = {'engine' : self .ident }
184+ md .update (status )
185+ self .session .send (stream , reply_type , metadata = md ,
186+ content = status , parent = msg , ident = idents )
187+ return False
188+ return True
189+
170190 def dispatch_shell (self , stream , msg ):
171191 """dispatch shell requests"""
172192 # flush control requests first
@@ -194,15 +214,7 @@ def dispatch_shell(self, stream, msg):
194214 self .log .debug ('\n *** MESSAGE TYPE:%s***' , msg_type )
195215 self .log .debug (' Content: %s\n --->\n ' , msg ['content' ])
196216
197- if msg_id in self .aborted :
198- self .aborted .remove (msg_id )
199- # is it safe to assume a msg_id will not be resubmitted?
200- reply_type = msg_type .split ('_' )[0 ] + '_reply'
201- status = {'status' : 'aborted' }
202- md = {'engine' : self .ident }
203- md .update (status )
204- self .session .send (stream , reply_type , metadata = md ,
205- content = status , parent = msg , ident = idents )
217+ if not self .should_handle (stream , msg , idents ):
206218 return
207219
208220 handler = self .shell_handlers .get (msg_type , None )
@@ -536,7 +548,7 @@ def do_is_complete(self, code):
536548 }
537549
538550 #---------------------------------------------------------------------------
539- # Engine methods
551+ # Engine methods (DEPRECATED)
540552 #---------------------------------------------------------------------------
541553
542554 def apply_request (self , stream , ident , parent ):
@@ -563,16 +575,16 @@ def apply_request(self, stream, ident, parent):
563575 parent = parent , ident = ident ,buffers = result_buf , metadata = md )
564576
565577 def do_apply (self , content , bufs , msg_id , reply_metadata ):
566- """Override in subclasses to support the IPython parallel framework.
567- """
578+ """DEPRECATED"""
568579 raise NotImplementedError
569580
570581 #---------------------------------------------------------------------------
571- # Control messages
582+ # Control messages (DEPRECATED)
572583 #---------------------------------------------------------------------------
573584
574585 def abort_request (self , stream , ident , parent ):
575586 """abort a specific msg by id"""
587+ self .log .warn ("abort_request is deprecated in kernel_base. It os only part of IPython parallel" )
576588 msg_ids = parent ['content' ].get ('msg_ids' , None )
577589 if isinstance (msg_ids , string_types ):
578590 msg_ids = [msg_ids ]
@@ -588,15 +600,13 @@ def abort_request(self, stream, ident, parent):
588600
589601 def clear_request (self , stream , idents , parent ):
590602 """Clear our namespace."""
603+ self .log .warn ("clear_request is deprecated in kernel_base. It os only part of IPython parallel" )
591604 content = self .do_clear ()
592605 self .session .send (stream , 'clear_reply' , ident = idents , parent = parent ,
593606 content = content )
594607
595608 def do_clear (self ):
596- """Override in subclasses to clear the namespace
597-
598- This is only required for IPython.parallel.
599- """
609+ """DEPRECATED"""
600610 raise NotImplementedError
601611
602612 #---------------------------------------------------------------------------
0 commit comments