async_utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:pyrpl 作者: lneuhaus 项目源码 文件源码
def _wait_for_done(self, timeout):
        """
        Will not return until either timeout expires or future becomes "done".
        There is one potential deadlock situation here:

        The deadlock occurs if we await_result while at the same
        time, this future needs to await_result from another future
        ---> To be safe, don't use await_result() in a Qt slot...
        """
        if self.cancelled():
            raise CancelledError("Future was cancelled")  # pragma: no-cover
        if not self.done():
            self.timer_timeout = None
            if (timeout is not None) and timeout > 0:
                self._timer_timeout = MainThreadTimer(timeout*1000)
                self._timer_timeout.timeout.connect(self._exit_loop)
                self._timer_timeout.start()
            self.loop = QtCore.QEventLoop()
            self.add_done_callback(self._exit_loop)
            self.loop.exec_()
            if self._timer_timeout is not None:
                if not self._timer_timeout.isActive():
                    return TimeoutError("Timeout occured")  # pragma: no-cover
                else:
                    self._timer_timeout.stop()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号