From f65b0da75a6a7c5f8daedb47edced87ad9b258e2 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 31 Mar 2021 19:19:36 +0000 Subject: [PATCH] =?UTF-8?q?threading=20minimal=20=20(lignes=201=20=C3=A0?= =?UTF-8?q?=2027)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Concurrent Programming.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Concurrent Programming.py b/Concurrent Programming.py index 857ff6e..18c49f5 100644 --- a/Concurrent Programming.py +++ b/Concurrent Programming.py @@ -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 datetime import timedelta from datetime import datetime