本文整理汇总了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()
示例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)
示例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
示例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...")
示例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()
示例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...")
示例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
示例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()
示例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
示例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
示例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
示例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))
示例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()
示例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
示例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