|
76 | 76 | from pygments.util import ClassNotFound
|
77 | 77 | from pygments.token import Token
|
78 | 78 |
|
| 79 | +import jupyter_client |
| 80 | + |
| 81 | + |
| 82 | +# jupyter_client 7.0+ has async channel methods that we expect to be sync here |
| 83 | +# also, `block` was removed from `get_msg()` |
| 84 | +if jupyter_client._version.version_info[0] >= 7: |
| 85 | + from jupyter_client.utils import run_sync |
| 86 | + JUPYTER_CLIENT_7 = True |
| 87 | +else: |
| 88 | + run_sync = lambda x: x |
| 89 | + JUPYTER_CLIENT_7 = False |
| 90 | + |
79 | 91 |
|
80 | 92 | def ask_yes_no(prompt, default=None, interrupt=None):
|
81 | 93 | """Asks a question and returns a boolean (y/n) answer.
|
@@ -705,8 +717,8 @@ def run_cell(self, cell, store_history=True):
|
705 | 717 | return
|
706 | 718 |
|
707 | 719 | # flush stale replies, which could have been ignored, due to missed heartbeats
|
708 |
| - while self.client.shell_channel.msg_ready(): |
709 |
| - self.client.shell_channel.get_msg() |
| 720 | + while run_sync(self.client.shell_channel.msg_ready)(): |
| 721 | + run_sync(self.client.shell_channel.get_msg)() |
710 | 722 | # execute takes 'hidden', which is the inverse of store_hist
|
711 | 723 | msg_id = self.client.execute(cell, not store_history)
|
712 | 724 |
|
@@ -739,7 +751,10 @@ def run_cell(self, cell, store_history=True):
|
739 | 751 | #-----------------
|
740 | 752 |
|
741 | 753 | def handle_execute_reply(self, msg_id, timeout=None):
|
742 |
| - msg = self.client.shell_channel.get_msg(block=False, timeout=timeout) |
| 754 | + kwargs = {"timeout": timeout} |
| 755 | + if not JUPYTER_CLIENT_7: |
| 756 | + kwargs["block"] = False |
| 757 | + msg = run_sync(self.client.shell_channel.get_msg)(**kwargs) |
743 | 758 | if msg["parent_header"].get("msg_id", None) == msg_id:
|
744 | 759 |
|
745 | 760 | self.handle_iopub(msg_id)
|
@@ -778,7 +793,10 @@ def handle_is_complete_reply(self, msg_id, timeout=None):
|
778 | 793 | ## Get the is_complete response:
|
779 | 794 | msg = None
|
780 | 795 | try:
|
781 |
| - msg = self.client.shell_channel.get_msg(block=True, timeout=timeout) |
| 796 | + kwargs = {"timeout": timeout} |
| 797 | + if not JUPYTER_CLIENT_7: |
| 798 | + kwargs["block"] = True |
| 799 | + msg = run_sync(self.client.shell_channel.get_msg)(**kwargs) |
782 | 800 | except Empty:
|
783 | 801 | warn('The kernel did not respond to an is_complete_request. '
|
784 | 802 | 'Setting `use_kernel_is_complete` to False.')
|
@@ -849,8 +867,8 @@ def handle_iopub(self, msg_id=''):
|
849 | 867 |
|
850 | 868 | It only displays output that is caused by this session.
|
851 | 869 | """
|
852 |
| - while self.client.iopub_channel.msg_ready(): |
853 |
| - sub_msg = self.client.iopub_channel.get_msg() |
| 870 | + while run_sync(self.client.iopub_channel.msg_ready)(): |
| 871 | + sub_msg = run_sync(self.client.iopub_channel.get_msg)() |
854 | 872 | msg_type = sub_msg['header']['msg_type']
|
855 | 873 |
|
856 | 874 | # Update execution_count in case it changed in another session
|
@@ -1003,7 +1021,7 @@ def handle_image_callable(self, data, mime):
|
1003 | 1021 | def handle_input_request(self, msg_id, timeout=0.1):
|
1004 | 1022 | """ Method to capture raw_input
|
1005 | 1023 | """
|
1006 |
| - req = self.client.stdin_channel.get_msg(timeout=timeout) |
| 1024 | + req = run_sync(self.client.stdin_channel.get_msg)(timeout=timeout) |
1007 | 1025 | # in case any iopub came while we were waiting:
|
1008 | 1026 | self.handle_iopub(msg_id)
|
1009 | 1027 | if msg_id == req["parent_header"].get("msg_id"):
|
@@ -1032,6 +1050,6 @@ def double_int(sig, frame):
|
1032 | 1050 |
|
1033 | 1051 | # only send stdin reply if there *was not* another request
|
1034 | 1052 | # or execution finished while we were reading.
|
1035 |
| - if not (self.client.stdin_channel.msg_ready() or |
1036 |
| - self.client.shell_channel.msg_ready()): |
| 1053 | + if not (run_sync(self.client.stdin_channel.msg_ready)() or |
| 1054 | + run_sync(self.client.shell_channel.msg_ready)()): |
1037 | 1055 | self.client.input(raw_data)
|
0 commit comments