當前位置: 首頁>>代碼示例>>Python>>正文


Python time.sleep方法代碼示例

本文整理匯總了Python中time.sleep方法的典型用法代碼示例。如果您正苦於以下問題:Python time.sleep方法的具體用法?Python time.sleep怎麽用?Python time.sleep使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在time的用法示例。


在下文中一共展示了time.sleep方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: draw_animation

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def draw_animation(image):
    # this is the original pimoroni function for drawing sprites
    try:

        for o_x in range(int(image.size[0] / width)):

            for o_y in range(int(image.size[1] / height)):

                valid = False

                for x in range(width):

                    for y in range(height):
                        pixel = image.getpixel(((o_x * width) + y, (o_y * height) + x))
                        r, g, b = int(pixel[0]), int(pixel[1]), int(pixel[2])
                        if r or g or b:
                            valid = True
                        unicorn.set_pixel(x, y, r, g, b)

                if valid:
                    unicorn.show()
                    time.sleep(cycle_time)

    except KeyboardInterrupt:
        unicorn.off() 
開發者ID:pimoroni,項目名稱:unicorn-hat-hd,代碼行數:27,代碼來源:weather-icons.py

示例2: show

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def show():
    """Output the contents of the buffer to Unicorn HAT HD."""
    setup()
    if _addressing_enabled:
        for address in range(8):
            display = _displays[address]
            if display.enabled:
                if _buffer_width == _buffer_height or _rotation in [0, 2]:
                    window = display.get_buffer_window(numpy.rot90(_buf, _rotation))
                else:
                    window = display.get_buffer_window(numpy.rot90(_buf, _rotation))

                _spi.xfer2([_SOF + 1 + address] + (window.reshape(768) * _brightness).astype(numpy.uint8).tolist())
                time.sleep(_DELAY)
    else:
        _spi.xfer2([_SOF] + (numpy.rot90(_buf, _rotation).reshape(768) * _brightness).astype(numpy.uint8).tolist())

    time.sleep(_DELAY) 
開發者ID:pimoroni,項目名稱:unicorn-hat-hd,代碼行數:20,代碼來源:__init__.py

示例3: n_steps

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def n_steps(self, steps=None, random=False):
        """
        Run for n steps.
        """
        if steps is None:
            steps = int(self.user.ask("Enter number of steps: "))
        target = self.period + steps
        self.user.tell("Running for %i steps; press Ctrl-c to halt!" % steps)
        time.sleep(3)
        try:
            while self.period < target:
                step_msg = self.step(random=random)
                if step_msg is not None:
                    self.user.tell(step_msg)
                    break
        except KeyboardInterrupt:
            pass 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:19,代碼來源:env.py

示例4: start

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def start(self):

        self._logger.info("Starting FLOW ingest") 
        self._watcher.start()
            
        try:
            while True:                
                self._ingest_files_pool()              
                time.sleep(self._ingestion_interval)
        except KeyboardInterrupt:
            self._logger.info("Stopping FLOW collector...")  
            Util.remove_kafka_topic(self._producer.Zookeeper, self._producer.Topic, self._logger)
            self._watcher.stop()
            self._pool.terminate()
            self._pool.close()            
            self._pool.join()
            SystemExit("Ingest finished...") 
開發者ID:apache,項目名稱:incubator-spot,代碼行數:19,代碼來源:collector.py

示例5: start

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def start(self):

        self._logger.info("Starting PROXY collector")
        self._watcher.start()   
    
        try:
            while True:
                #self._ingest_files()
                self._ingest_files_pool()              
                time.sleep(self._ingestion_interval)
        except KeyboardInterrupt:
            self._logger.info("Stopping Proxy collector...")  
            Util.remove_kafka_topic(self._kafka_topic.Zookeeper,self._kafka_topic.Topic,self._logger)          
            self._watcher.stop()
            self._pool.terminate()
            self._pool.close()            
            self._pool.join() 
開發者ID:apache,項目名稱:incubator-spot,代碼行數:19,代碼來源:collector.py

示例6: start

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def start(self):

        self._logger.info("Starting DNS ingest")
        self._watcher.start()

        try:
            while True:
                self._ingest_files_pool()
                time.sleep(self._ingestion_interval)
        except KeyboardInterrupt:
            self._logger.info("Stopping DNS collector...")
            Util.remove_kafka_topic(self._producer.Zookeeper, self._producer.Topic, self._logger)
            self._watcher.stop()
            self._pool.terminate()
            self._pool.close()
            self._pool.join()
            SystemExit("Ingest finished...") 
開發者ID:apache,項目名稱:incubator-spot,代碼行數:19,代碼來源:collector.py

示例7: clickOnAirplane

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def clickOnAirplane(self, text):
        '''
        clickOnAirplane()
        Clicks on the airplane with the name text, and then takes a screenshot
        '''
        try:
            element = self.browser.find_elements_by_xpath("//td[text()='%s']" % text.lower())
            print("number of elements found: %i" % len(element))
            if len(element) > 0:
                print("clicking on {}!".format(text))
                element[0].click()
                time.sleep(0.5) # if we don't wait a little bit the airplane icon isn't drawn.
                return self.screenshot('tweet.png')
            else:
                print("couldn't find the object")
        except Exception as e:
            util.error("Could not click on airplane: {}".format(e))
            return None 
開發者ID:kevinabrandon,項目名稱:AboveTustin,代碼行數:20,代碼來源:screenshot.py

示例8: test_min_and_max_seconds_between_redraws

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def test_min_and_max_seconds_between_redraws(ansi_bar, ansi_io):
    ansi_bar.min_seconds_between_redraws(0.5)
    ansi_bar.max_seconds_between_redraws(2 - 1)

    ansi_bar.start()
    ansi_bar.set_progress(1)
    time.sleep(1)
    ansi_bar.set_progress(2)
    time.sleep(2)
    ansi_bar.set_progress(3)

    output = [
        "    0 [>---------------------------]",
        "    2 [->--------------------------]",
        "    3 [--->------------------------]",
    ]

    expected = "\x0D" + "\x0D".join(output)

    assert expected == ansi_io.fetch_error() 
開發者ID:sdispater,項目名稱:clikit,代碼行數:22,代碼來源:test_progress_bar.py

示例9: run

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def run(self):
        """
        Loop on, wait for events until manual interruption.
        """
        # start
        print "Waiting for the robot to be in wake up position"
        self.motion.wakeUp()

        print "Starting HumanGreeter"
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            print "Interrupted by user, stopping HumanGreeter"
            self.face_detection.unsubscribe("HumanGreeter")
            #stop
            sys.exit(0)

        return 
開發者ID:maverickjoy,項目名稱:pepper-robot-programming,代碼行數:21,代碼來源:human_greeter.py

示例10: _startImageCapturingAtGraphNode

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def _startImageCapturingAtGraphNode(self):
        amntY = 0.3
        xdir = [-0.5, 0, 0.5]
        cameraId = 0

        for idx,amntX in enumerate(xdir):
            self._moveHead(amntX, amntY)
            time.sleep(0.1)
            self._checkIfAsthamaInEnvironment(cameraId)
            if self.pumpFound :
                # Setting rotation angle of body towards head
                theta = 0
                if idx == 0: # LEFT
                    theta = math.radians(-45)
                if idx == 2: # RIGHT
                    theta = math.radians(45)
                self.pumpAngleRotation = theta

                return "KILLING GRAPH SEARCH : PUMP FOUND"

        self._moveHead(0, 0) # Bringing to initial view

        return 
開發者ID:maverickjoy,項目名稱:pepper-robot-programming,代碼行數:25,代碼來源:asthama_search.py

示例11: start

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def start(self):
        """Start executing this action."""
        self.logger.debug("Starting Noop Action.")
        self.task.set_status(hd_fields.TaskStatus.Running)
        self.task.save()
        time.sleep(5)
        self.task = self.state_manager.get_task(self.task.get_id())
        if self.task.check_terminate():
            self.logger.debug("Terminating action.")
            self.task.set_status(hd_fields.TaskStatus.Terminated)
            self.task.failure()
            self.task.add_status_msg(
                msg="Action terminated.", ctx_type='NA', ctx='NA', error=False)
        else:
            self.logger.debug("Marked task as successful.")
            self.task.set_status(hd_fields.TaskStatus.Complete)
            target_nodes = self.orchestrator.get_target_nodes(self.task)
            for n in target_nodes:
                self.task.success(focus=n.name)
            self.task.add_status_msg(
                msg="Noop action.", ctx_type='NA', ctx='NA', error=False)
        self.task.save()
        self.logger.debug("Saved task state.")
        self.logger.debug("Finished Noop Action.")
        return 
開發者ID:airshipit,項目名稱:drydock,代碼行數:27,代碼來源:orchestrator.py

示例12: collect_subtasks

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def collect_subtasks(self, action=None, poll_interval=15, timeout=300):
        """Monitor subtasks waiting for completion.

        If action is specified, only watch subtasks executing this action. poll_interval
        and timeout are measured in seconds and used for controlling the monitoring behavior.

        :param action: What subtask action to monitor
        :param poll_interval: How often to load subtask status from the database
        :param timeout: How long to continue monitoring before considering subtasks as hung
        """
        timeleft = timeout
        while timeleft > 0:
            st_list = self.statemgr.get_active_subtasks(self.task_id)
            if len(st_list) == 0:
                return True
            else:
                time.sleep(poll_interval)
                timeleft = timeleft - poll_interval

        raise errors.CollectTaskTimeout(
            "Timed out collecting subtasks for task %s." % str(self.task_id)) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:23,代碼來源:task.py

示例13: poweroff_node

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def poweroff_node(self, node):
        """Power off a node."""
        ses = self.init_session(node)
        domain = ses.lookupByName(node.name)

        if domain.isActive():
            domain.destroy()
        else:
            self.logger.debug("Node already powered off.")
            return

        try:
            i = 3
            while i > 0:
                self.logger.debug("Polling powerstate waiting for success.")
                power_state = domain.isActive()
                if not power_state:
                    return
                time.sleep(10)
                i = i - 1
            raise errors.DriverError("Power state never matched off")
        finally:
            ses.close() 
開發者ID:airshipit,項目名稱:drydock,代碼行數:25,代碼來源:oob.py

示例14: execute_task

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def execute_task(self, task_id):
        task = self.state_manager.get_task(task_id)
        task_action = task.action

        if task_action in self.supported_actions:
            # Just use the Noop action
            task_action = Noop(task, self.orchestrator, self.state_manager)
            task_runner = DriverActionRunner(task_action)
            task_runner.start()

            while task_runner.is_alive():
                time.sleep(1)

            return
        else:
            raise errors.DriverError("Unsupported action %s for driver %s" %
                                     (task_action, self.driver_desc))


# Execute a single task in a separate thread 
開發者ID:airshipit,項目名稱:drydock,代碼行數:22,代碼來源:driver.py

示例15: invoke

# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep [as 別名]
def invoke(self):
        """Invoke execution of this action."""
        task = self.api_client.create_task(
            design_ref=self.design_ref,
            task_action=self.action_name,
            node_filter=self.node_filter)

        if not self.block:
            return task

        task_id = task.get('task_id')

        while True:
            time.sleep(self.poll_interval)
            task = self.api_client.get_task(task_id=task_id)
            if task.get('status',
                        '') in [TaskStatus.Complete, TaskStatus.Terminated]:
                return task 
開發者ID:airshipit,項目名稱:drydock,代碼行數:20,代碼來源:actions.py


注:本文中的time.sleep方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。