diff --git a/spyder_kernels/comms/frontendcomm.py b/spyder_kernels/comms/frontendcomm.py index f23fa196..637a188e 100644 --- a/spyder_kernels/comms/frontendcomm.py +++ b/spyder_kernels/comms/frontendcomm.py @@ -128,10 +128,11 @@ def _check_comm_reply(self): """ Send comm message to frontend to check if the iopub channel is ready """ - if len(self._pending_comms) == 0: - return - for comm in self._pending_comms.values(): - self._notify_comm_ready(comm) + with self.comm_lock: + if len(self._pending_comms) == 0: + return + for comm in self._pending_comms.values(): + self._notify_comm_ready(comm) self.kernel.io_loop.call_later(1, self._check_comm_reply) def _notify_comm_ready(self, comm): @@ -143,7 +144,8 @@ def _notify_comm_ready(self, comm): def _comm_ready_callback(self, ret): """A comm has replied, so process all cached messages related to it.""" - comm = self._pending_comms.pop(self.calling_comm_id, None) + with self.comm_lock: + comm = self._pending_comms.pop(self.calling_comm_id, None) if not comm: return # Cached messages for that comm @@ -177,7 +179,8 @@ def _comm_open(self, comm, msg): # IOPub might not be connected yet, keep sending messages until a # reply is received. - self._pending_comms[comm.comm_id] = comm + with self.comm_lock: + self._pending_comms[comm.comm_id] = comm self._notify_comm_ready(comm) self.kernel.io_loop.call_later(.3, self._check_comm_reply)