from threading import Thread
from time import sleep
def hard_calculations():
# some calculations...
sleep(0.3)
class CustomThread(Thread):
def __init__(self):
super().__init__()
self._result = None
def run(self) -> None:
threads = []
for i in range(5):
t = Thread(target=hard_calculations)
t.start()
threads.append(t)
# Дожидаемся выполнения всех потоков
for thread in threads:
thread.join()
print(f'{self.name} is done!')
self._result = 'furfurfur'
@property
def result(self):
return self._result
if __name__ == '__main__':
t = CustomThread()
t.start()
t.join() # Дожидаемся завершения нашего `главного` потока
print(t.result)