First scheme (preparing tools)

This commit is contained in:
Jean Sirmai 2021-03-30 16:56:55 +00:00
parent dd2a8044ea
commit a7c44bfbad
1 changed files with 65 additions and 26 deletions

View File

@ -1,33 +1,73 @@
import threading
from threading import Thread
from datetime import timedelta
from datetime import datetime
import random
import time
renew_length = 12
local_workers_number = 10
number_of_cycles = 20
renew = []
done = []
space = []
copy = []
def init():
for i in range(0, renew_length - 1):
renew.append(-1)
for j in range(0, local_workers_number):
space.append(random.randint(10,99))
copy.append(space[j])
print(' ',space,' < initial global state')
def disp(coord, id, start, prev, next):
print(' {} at [{}] {} > {} by thread n°{:>3} {!s:.4} {}'.format(
space,
coord,
prev,
next,
str(id),
datetime.now().timestamp() - start,
renew
)
)
def local_worker(coord, id):
start = datetime.now().timestamp()
val = random.randint(1,1000)
time.sleep(val / 1000)
prev = space[coord]
next = space[coord] = 10 + val % 89
print('{} on [{}] : {} > {} by local thread n°{:>3} {!s:.4}'.format(
space,
coord,
prev,
next,
str(id),
datetime.now().timestamp() - start
)
)
done.append(id)
for i in renew:
if renew[i] == id:
renew[i] = -1
break
disp(coord, id, start, prev, next)
from threading import Thread
space = []
for i in range(0,10):
space.append(random.randint(10,99))
print(space,' < initialglobal state')
for k in range (1,20):
init()
for k in range (1, number_of_cycles):
n = 0
while renew[n] == -1: # a diagonal of zeros is expected !
renew[n] = 0
if n < renew_length - 2:
n += 1
break
# for n in range(0, renew_length - 1):
# if renew[n] == -1:
# renew[n] = 0
# break
t = Thread(target=local_worker, args=(random.randint(0, len(space) - 1), k))
t.start()
time.sleep(1)
print(' ',copy,' < initial global state (to compare)')
print(done)
done.sort()
print(done)
"""
@ -61,4 +101,3 @@ Il délègue à la **CLI** les fonctions de communications avec les modules pér
3. mesures / recueil des commandes / retour d'information
"""