JustCaptain kod-buduschego
1b7ae631e8e0aa08482b2abc32064a70d25c5de5
Перейти к файлу
Код
kod-buduschego Python 2025-20264.5. Многопоточностьexample_2.py
anc update c70a58f 8 октября 2026 г.
example_2.py
from threading import Thread
import time

RESULT: list[int] = []

numbers: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def sum_worker(nums: list[int], second: int) -> None:
    time.sleep(second)
    RESULT.append(sum(nums))


th_one = Thread(target=sum_worker, args=(numbers[:5], 3))
th_two = Thread(target=sum_worker, args=(numbers[5:], 5))

th_one.start()
th_two.start()

th_two.join()

print(RESULT)