Files
courses/py3interm/EXAMPLES/thr_simple.py
T
2025-05-20 11:57:43 -04:00

23 lines
421 B
Python

#!/usr/bin/env python
from threading import Thread
import random
import time
class SimpleThread(Thread):
def __init__(self, num):
super().__init__() # <1>
self._threadnum = num
def run(self): # <2>
time.sleep(random.randint(1, 3))
print("Hello from thread {}".format(self._threadnum))
for i in range(10):
t = SimpleThread(i) # <3>
t.start() # <4>
print("Done.")