threading minimal (lignes 1 à 27)

This commit is contained in:
Jean Sirmai 2021-03-31 19:19:36 +00:00
parent be9ab52204
commit f65b0da75a
1 changed files with 32 additions and 0 deletions

View File

@ -1,3 +1,35 @@
from threading import Thread
import random # juste pour que le temps de travail des threads soit aléatoire
import time
arrows = []
local_threads_number = 10
def init():
for j in range(0, local_threads_number):
arrows.append(j % 10)
print(arrows,' < initial arrows state')
def local_thread(coord):
while True:
time.sleep(random.randint(0,1))
arrows[coord] = (arrows[coord] + 1) % 10
print(arrows,' ',coord)
return
init() # Scheduler
for i in range(0, local_threads_number):
t = Thread(target=local_thread, args=(range(i,i+1)))
# argument after * must be an iterable, not int < ?
t.start()
# Je ne l'isole pas dans un autre fichier
###########################################################################################
from threading import Thread from threading import Thread
from datetime import timedelta from datetime import timedelta
from datetime import datetime from datetime import datetime