diff --git a/spyder_kernels/comms/commbase.py b/spyder_kernels/comms/commbase.py index ddc90ee9..800078f9 100644 --- a/spyder_kernels/comms/commbase.py +++ b/spyder_kernels/comms/commbase.py @@ -8,7 +8,7 @@ Class that handles communications between Spyder kernel and frontend. Comms transmit data in a list of buffers, and in a json-able dictionnary. -Here, we only support json to avoid issues of compatibility between python +Here, we only support json to avoid issues of compatibility between Python versions. In the abstraction below, buffers is used to send bytes. The messages exchanged have the following msg_dict: @@ -17,7 +17,7 @@ msg_dict = { 'spyder_msg_type': spyder_msg_type, 'content': content, - } + } ``` To simplify the usage of messaging, we use a higher level function calling @@ -269,8 +269,7 @@ def _send_message( comm_id: int the comm to send to. If None sends to all comms. buffers: list(bytes) - a list of bytes to send - + a list of bytes to send. """ if not self.is_open(comm_id): raise CommError("The comm is not connected.") @@ -279,7 +278,7 @@ def _send_message( msg_dict = { 'spyder_msg_type': spyder_msg_type, 'content': content, - } + } self._comms[comm_id]['comm'].send(msg_dict, buffers=buffers) @@ -318,7 +317,7 @@ def _register_comm(self, comm): self._comms[comm.comm_id] = { 'comm': comm, 'status': 'opening', - } + } def _comm_close(self, msg): """Close comm.""" @@ -395,10 +394,12 @@ def _set_call_return_value(self, call_dict, return_value, is_error=False): if not send_reply: # Nothing to send back return + buffers = None if isinstance(return_value, bytes): buffers = [return_value] return_value = None + content = { 'is_error': is_error, 'call_id': call_dict['call_id'], @@ -407,7 +408,9 @@ def _set_call_return_value(self, call_dict, return_value, is_error=False): } self._send_message( - 'remote_call_reply', content=content, comm_id=self.calling_comm_id, + 'remote_call_reply', + content=content, + comm_id=self.calling_comm_id, buffers=buffers ) @@ -461,7 +464,6 @@ def _get_call_return_value(self, call_dict, comm_id): self._wait_reply(comm_id, call_id, call_name, timeout) content = self._reply_inbox.pop(call_id) - return_value = content['call_return_value'] if content['is_error']: @@ -483,6 +485,7 @@ def _handle_remote_call_reply(self, msg_dict, buffers): call_name = content['call_name'] is_error = content['is_error'] return_value = content['call_return_value'] + # Prepare return value if is_error: return_value = CommsErrorWrapper.from_json(return_value) @@ -572,11 +575,13 @@ def __call__(self, *args, **kwargs): buffered_args = [] buffered_kwargs = [] args = list(args) + for i, arg in enumerate(args): if isinstance(arg, bytes): buffers.append(arg) buffered_args.append(i) args[i] = None + for name in kwargs: arg = kwargs[name] if isinstance(arg, bytes): @@ -593,7 +598,7 @@ def __call__(self, *args, **kwargs): 'call_kwargs': kwargs, 'buffered_args': buffered_args, 'buffered_kwargs': buffered_kwargs - } + } if not self._comms_wrapper.is_open(self._comm_id): # Only an error if the call is blocking. diff --git a/spyder_kernels/console/kernel.py b/spyder_kernels/console/kernel.py index 3a6bfa22..da595371 100644 --- a/spyder_kernels/console/kernel.py +++ b/spyder_kernels/console/kernel.py @@ -276,9 +276,11 @@ def get_current_frames(self, ignore_internal_threads=True): thread_name = thread_names[thread_id] else: thread_name = str(thread_id) + # Transform stack in a dict because FrameSummary objects - # are not compatible between versions of python + # are not compatible between versions of Python stack_dict[thread_name] = stacksummary_to_json(stack) + return stack_dict # --- For the Variable Explorer @@ -365,6 +367,7 @@ def set_value(self, name, value, encoded=False): if encoded: # Decode_value value = cloudpickle.loads(value) + ns = self.shell._get_reference_namespace(name) ns[name] = value self.log.debug(ns)