PROJET AUTOBLOG


shaarli-Links

Site original : shaarli-Links

⇐ retour index

threading en python

mardi 18 janvier 2022 à 15:26
import threading
import time

def thread_function(num):
  print(f"start thread {num}")
  time.sleep(5)
  print(f"stop thread {num}")

for a in range(5):
  x = threading.Thread(target=thread_function, args=(a,))
  x.start()

while threading.active_count() > 1:
    print(f"\rnb thread : {threading.active_count()}", end='', flush=True)
    time.sleep(1)

print('fini')

Permalink