当前位置: 首页>>代码示例>>Python>>正文


Python Timer.sleep方法代码示例

本文整理汇总了Python中timer.Timer.sleep方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.sleep方法的具体用法?Python Timer.sleep怎么用?Python Timer.sleep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在timer.Timer的用法示例。


在下文中一共展示了Timer.sleep方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wait_for_task_to_complete

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import sleep [as 别名]
    def wait_for_task_to_complete(self, timeout=600):

        timer = Timer()

        timer.start()

        while True:
            timer.print_time_elapsed()
            print("Checking status of task.")

            if timer.has_timeout(timeout):
                raise TimeOutError("Task timed out after " + str(timeout) +
                                   " seconds.")

            if self.is_task_completed():
                print("Task Completed!")
                return

            timer.sleep(3)
开发者ID:ibm-security-intelligence,项目名称:api-samples,代码行数:21,代码来源:taskManager.py

示例2: TableWindow

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import sleep [as 别名]

#.........这里部分代码省略.........
        self.cols.append(self.col_five_edit)
        self.cols.append(self.col_six_edit)
        self.cols.append(self.col_seven_edit)
        self.cols.append(self.col_eight_edit)
        self.cols.append(self.col_nine_edit)
        self.cols.append(self.col_ten_edit)

    def read_table(self):
        """Прочита таблицата от Table и я попълва в UI-a.
        Ако има победител, пуска нов прозер.
        """
        result = ""
        i = 0
        for col in self.cols:
            for j in range(0, len(self.t.matrix)):
                result += self.t.matrix[j][i] + "\n-\n"
            i += 1
            col.setText(result)
            result = ""
        if self.t.has_winner():
            if self.t.get_winner() == Table.RED:
                print(self.first_player_time.stop())
                self.player_game_time.setText(str(self.first_player_time.stop()))
                self.win_dialog.show()
            else:
                self.compuret_win.show()

    def first_button_clicked(self):
        """Метод, който се извиква при натискането на първия бутон.
        Извършва ход в играта на позиция 0.
        """
        if self.onTurn == 1:
            self.t.commit_turn(0, "R")
            self.first_player_time.sleep()
            if self.vsPC:
                pos = self.pc.get_turn(self.t.matrix)
                self.t.commit_turn(pos, "B")
                self.first_player_time.start()
            else:
                self.onTurn = 2
                self.player.setText("B")
        else:
            self.t.commit_turn(0, "B")
            self.player.setText("R")
            self.onTurn = 1
            self.first_player_time.start()
        self.read_table()

    def second_button_clicked(self):
        """Метод, който се извиква при натискането на втория бутон.
        Извършва ход в играта на позиция 1.
        """
        if self.onTurn == 1:
            self.t.commit_turn(1, "R")
            self.first_player_time.sleep()
            if self.vsPC:
                self.t.commit_turn(self.pc.get_turn(
                    self.t.matrix), "B")
                self.first_player_time.start()
            else:
                self.onTurn = 2
                self.player.setText("B")
        else:
            self.t.commit_turn(1, "B")
            self.player.setText("R")
            self.onTurn = 1
开发者ID:stoianivanov,项目名称:Connect-Four,代码行数:70,代码来源:connect_four.py


注:本文中的timer.Timer.sleep方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。