import time
from threading import Thread, Lock  #потоки threading продовжують працювати при закритті основного потоку

count = 0

lock = Lock()

def worker():
    global count
    for _ in range(5):
        with lock:
            count +=1
            time.sleep(.5)
            print(count)
            count +=1

threads = []

for i in range(10):
    thread = Thread(name=f'(i)', target=worker, args=())
    thread.daemon = True    #параметр завершує дочірні потоки при закритті основного
    threads.append(thread)      #ініціалізуємо потоки

for thread in threads:
    thread.start()      #запускаємо потоки

for thread in threads:
    thread.join()       #join очікує закінчення виконання дочірніх потоків

print('count = ',count)
ba0410a2123f92e7b07cba35289e810e7134acfa
<mask token>


def worker():
    global count
    for _ in range(5):
        with lock:
            count += 1
            time.sleep(0.5)
            print(count)
            count += 1


<mask token>

<mask token>


def worker():
    global count
    for _ in range(5):
        with lock:
            count += 1
            time.sleep(0.5)
            print(count)
            count += 1


<mask token>
for i in range(10):
    thread = Thread(name=f'(i)', target=worker, args=())
    thread.daemon = True
    threads.append(thread)
for thread in threads:
    thread.start()
for thread in threads:
    thread.join()
print('count = ', count)

<mask token>
count = 0
lock = Lock()


def worker():
    global count
    for _ in range(5):
        with lock:
            count += 1
            time.sleep(0.5)
            print(count)
            count += 1


threads = []
for i in range(10):
    thread = Thread(name=f'(i)', target=worker, args=())
    thread.daemon = True
    threads.append(thread)
for thread in threads:
    thread.start()
for thread in threads:
    thread.join()
print('count = ', count)

import time
from threading import Thread, Lock
count = 0
lock = Lock()


def worker():
    global count
    for _ in range(5):
        with lock:
            count += 1
            time.sleep(0.5)
            print(count)
            count += 1


threads = []
for i in range(10):
    thread = Thread(name=f'(i)', target=worker, args=())
    thread.daemon = True
    threads.append(thread)
for thread in threads:
    thread.start()
for thread in threads:
    thread.join()
print('count = ', count)

import time
from threading import Thread, Lock  #потоки threading продовжують працювати при закритті основного потоку

count = 0

lock = Lock()

def worker():
    global count
    for _ in range(5):
        with lock:
            count +=1
            time.sleep(.5)
            print(count)
            count +=1

threads = []

for i in range(10):
    thread = Thread(name=f'(i)', target=worker, args=())
    thread.daemon = True    #параметр завершує дочірні потоки при закритті основного
    threads.append(thread)      #ініціалізуємо потоки

for thread in threads:
    thread.start()      #запускаємо потоки

for thread in threads:
    thread.join()       #join очікує закінчення виконання дочірніх потоків

print('count = ',count)