Comment faire un délai dans Python

Mots clés : pythonpython-3.xdelaysleeptimedelaypython

meilleur 5 Réponses Comment faire un délai dans Python

vote vote


import time time.sleep(5)   # Delays for 5 seconds. You can also use a float value. 
import time while True:     print("This prints once a minute.")     time.sleep(60) # Delay for 1 minute (60 seconds). 
vote vote


from time import sleep sleep(0.1) # Time in seconds 
vote vote


>>> from time import sleep  >>> sleep(4) 
>>> def party_time(): ...     print('hooray!') ... >>> sleep(3); party_time() hooray! 
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor, as_completed from time import sleep, time  def party_later(kind='', n=''):     sleep(3)     return kind + n + ' party time!: ' + __name__  def main():     with ProcessPoolExecutor() as proc_executor:         with ThreadPoolExecutor() as thread_executor:             start_time = time()             proc_future1 = proc_executor.submit(party_later, kind='proc', n='1')             proc_future2 = proc_executor.submit(party_later, kind='proc', n='2')             thread_future1 = thread_executor.submit(party_later, kind='thread', n='1')             thread_future2 = thread_executor.submit(party_later, kind='thread', n='2')             for f in as_completed([               proc_future1, proc_future2, thread_future1, thread_future2,]):                 print(f.result())             end_time = time()     print('total time to execute four 3-sec functions:', end_time - start_time)  if __name__ == '__main__':     main() 
thread1 party time!: __main__ thread2 party time!: __main__ proc1 party time!: __mp_main__ proc2 party time!: __mp_main__ total time to execute four 3-sec functions: 3.4519670009613037 
>>> from threading import Timer >>> t = Timer(3, party_time, args=None, kwargs=None) >>> t.start() >>> >>> hooray!  >>> 
vote vote


import time time.sleep(5) # Delay for 5 seconds. 
self.wait.until(EC.presence_of_element_located((By.ID, 'UserName')) 
vote vote


import time print('Hello') time.sleep(5) # Number of seconds print('Bye') 
import pygame # If you are going to use the time module # don't do "from pygame import *" pygame.init() print('Hello') pygame.time.wait(5000) # Milliseconds print('Bye') 
import matplotlib print('Hello') matplotlib.pyplot.pause(5) # Seconds print('Bye') 
import tkinter as tk # Tkinter for Python 2 root = tk.Tk() print('Hello') def ohhi():     print('Oh, hi!') root.after(5000, ohhi) # Milliseconds and then a function print('Bye') 
import asyncio asyncio.sleep(5) 

Questions similaires