@@ -566,10 +566,12 @@ async def execute_request(self, stream, ident, parent):
566566 self .execution_count += 1
567567 self ._publish_execute_input (code , parent , self .execution_count )
568568
569- reply_content = await self .do_execute (
569+ reply_content = self .do_execute (
570570 code , silent , store_history ,
571571 user_expressions , allow_stdin ,
572572 )
573+ if inspect .isawaitable (reply_content ):
574+ reply_content = await reply_content
573575
574576 # Flush output before sending the reply.
575577 sys .stdout .flush ()
@@ -593,7 +595,7 @@ async def execute_request(self, stream, ident, parent):
593595 if not silent and reply_msg ['content' ]['status' ] == 'error' and stop_on_error :
594596 await self ._abort_queues ()
595597
596- async def do_execute (self , code , silent , store_history = True ,
598+ def do_execute (self , code , silent , store_history = True ,
597599 user_expressions = None , allow_stdin = False ):
598600 """Execute user code. Must be overridden by subclasses.
599601 """
@@ -604,11 +606,14 @@ async def complete_request(self, stream, ident, parent):
604606 code = content ['code' ]
605607 cursor_pos = content ['cursor_pos' ]
606608
607- matches = await self .do_complete (code , cursor_pos )
609+ matches = self .do_complete (code , cursor_pos )
610+ if inspect .isawaitable (matches ):
611+ matches = await matches
612+
608613 matches = json_clean (matches )
609614 self .session .send (stream , "complete_reply" , matches , parent , ident )
610615
611- async def do_complete (self , code , cursor_pos ):
616+ def do_complete (self , code , cursor_pos ):
612617 """Override in subclasses to find completions.
613618 """
614619 return {'matches' : [],
@@ -620,32 +625,37 @@ async def do_complete(self, code, cursor_pos):
620625 async def inspect_request (self , stream , ident , parent ):
621626 content = parent ['content' ]
622627
623- reply_content = await self .do_inspect (
628+ reply_content = self .do_inspect (
624629 content ['code' ], content ['cursor_pos' ],
625630 content .get ('detail_level' , 0 ),
626631 )
632+ if inspect .isawaitable (reply_content ):
633+ reply_content = await reply_content
634+
627635 # Before we send this object over, we scrub it for JSON usage
628636 reply_content = json_clean (reply_content )
629637 msg = self .session .send (stream , 'inspect_reply' ,
630638 reply_content , parent , ident )
631639 self .log .debug ("%s" , msg )
632640
633- async def do_inspect (self , code , cursor_pos , detail_level = 0 ):
641+ def do_inspect (self , code , cursor_pos , detail_level = 0 ):
634642 """Override in subclasses to allow introspection.
635643 """
636644 return {'status' : 'ok' , 'data' : {}, 'metadata' : {}, 'found' : False }
637645
638646 async def history_request (self , stream , ident , parent ):
639647 content = parent ['content' ]
640648
641- reply_content = await self .do_history (** content )
649+ reply_content = self .do_history (** content )
650+ if inspect .isawaitable (reply_content ):
651+ reply_content = await reply_content
642652
643653 reply_content = json_clean (reply_content )
644654 msg = self .session .send (stream , 'history_reply' ,
645655 reply_content , parent , ident )
646656 self .log .debug ("%s" , msg )
647657
648- async def do_history (self , hist_access_type , output , raw , session = None , start = None ,
658+ def do_history (self , hist_access_type , output , raw , session = None , start = None ,
649659 stop = None , n = None , pattern = None , unique = False ):
650660 """Override in subclasses to access history.
651661 """
@@ -698,7 +708,9 @@ async def comm_info_request(self, stream, ident, parent):
698708 self .log .debug ("%s" , msg )
699709
700710 async def shutdown_request (self , stream , ident , parent ):
701- content = await self .do_shutdown (parent ['content' ]['restart' ])
711+ content = self .do_shutdown (parent ['content' ]['restart' ])
712+ if inspect .isawaitable (content ):
713+ content = await content
702714 self .session .send (stream , 'shutdown_reply' , content , parent , ident = ident )
703715 # same content, but different msg_id for broadcasting on IOPub
704716 self ._shutdown_message = self .session .msg ('shutdown_reply' ,
@@ -715,7 +727,7 @@ async def shutdown_request(self, stream, ident, parent):
715727 shell_io_loop = self .shell_stream .io_loop
716728 shell_io_loop .add_callback (shell_io_loop .stop )
717729
718- async def do_shutdown (self , restart ):
730+ def do_shutdown (self , restart ):
719731 """Override in subclasses to do things when the frontend shuts down the
720732 kernel.
721733 """
@@ -725,21 +737,25 @@ async def is_complete_request(self, stream, ident, parent):
725737 content = parent ['content' ]
726738 code = content ['code' ]
727739
728- reply_content = await self .do_is_complete (code )
740+ reply_content = self .do_is_complete (code )
741+ if inspect .isawaitable (reply_content ):
742+ reply_content = await reply_content
729743 reply_content = json_clean (reply_content )
730744 reply_msg = self .session .send (stream , 'is_complete_reply' ,
731745 reply_content , parent , ident )
732746 self .log .debug ("%s" , reply_msg )
733747
734- async def do_is_complete (self , code ):
748+ def do_is_complete (self , code ):
735749 """Override in subclasses to find completions.
736750 """
737751 return { 'status' : 'unknown' }
738752
739753 async def debug_request (self , stream , ident , parent ):
740754 content = parent ['content' ]
741755
742- reply_content = await self .do_debug_request (content )
756+ reply_content = self .do_debug_request (content )
757+ if inspect .isawaitable (reply_content ):
758+ reply_content = await reply_content
743759 reply_content = json_clean (reply_content )
744760 reply_msg = self .session .send (stream , 'debug_reply' , reply_content ,
745761 parent , ident )
@@ -775,7 +791,7 @@ async def apply_request(self, stream, ident, parent):
775791 self .session .send (stream , 'apply_reply' , reply_content ,
776792 parent = parent , ident = ident ,buffers = result_buf , metadata = md )
777793
778- async def do_apply (self , content , bufs , msg_id , reply_metadata ):
794+ def do_apply (self , content , bufs , msg_id , reply_metadata ):
779795 """DEPRECATED"""
780796 raise NotImplementedError
781797
@@ -806,7 +822,7 @@ async def clear_request(self, stream, idents, parent):
806822 self .session .send (stream , 'clear_reply' , ident = idents , parent = parent ,
807823 content = content )
808824
809- async def do_clear (self ):
825+ def do_clear (self ):
810826 """DEPRECATED since 4.0.3"""
811827 raise NotImplementedError
812828
0 commit comments