Пример #1
0
    def _wait_reply(self, call_id, call_name, timeout, retry=True):
        """Wait until the frontend replies to a request."""
        def reply_received():
            """The reply is there!"""
            return call_id in self._reply_inbox

        if not self.wait_until(reply_received):
            if retry:
                self._wait_reply(call_id, call_name, timeout, False)
                return
            raise TimeoutError(
                "Timeout while waiting for '{}' reply.".format(call_name))
Пример #2
0
    def _wait_reply(self, call_id, call_name, timeout):
        """Wait until the frontend replies to a request."""
        if call_id in self._reply_inbox:
            return

        t_start = time.time()
        while call_id not in self._reply_inbox:
            if time.time() > t_start + timeout:
                raise TimeoutError(
                    "Timeout while waiting for '{}' reply".format(call_name))
            if threading.current_thread() is self.comm_socket_thread:
                # Wait for a reply on the comm channel.
                self.poll_one()
            else:
                # Wait 10ms for a reply
                time.sleep(0.01)
Пример #3
0
 def _wait_reply(self, call_id, call_name, timeout, retry=True):
     """Wait until the frontend replies to a request."""
     if call_id in self._reply_inbox:
         return
     # Send config again just in case
     self._send_comm_config()
     t_start = time.time()
     while call_id not in self._reply_inbox:
         if time.time() > t_start + timeout:
             if retry:
                 self._wait_reply(call_id, call_name, timeout, False)
                 return
             raise TimeoutError(
                 "Timeout while waiting for '{}' reply.".format(call_name))
         if threading.current_thread() is self.comm_socket_thread:
             # Wait for a reply on the comm channel.
             self.poll_one()
         else:
             # Wait 10ms for a reply
             time.sleep(0.01)
Пример #4
0
    def _wait_reply(self, call_id, call_name, timeout):
        """Wait until the frontend replies to a request."""
        if call_id in self._reply_inbox:
            return

        # There is no get_ident in Py2
        if not PY2 and self._main_thread_id != threading.get_ident():
            # We can't call kernel.do_one_iteration from this thread.
            # And we have no reason to think the main thread is not busy.
            raise CommError("Can't make blocking calls from non-main threads.")

        t_start = time.time()
        while call_id not in self._reply_inbox:
            if time.time() > t_start + timeout:
                raise TimeoutError(
                    "Timeout while waiting for '{}' reply".format(call_name))
            priority = 0
            while priority is not None:
                priority = self.kernel.do_one_iteration()
                if priority is not None:
                    # For Python2
                    priority = priority.result()