Skip to content

Commit d48c443

Browse files
Create threading_enum.py
1 parent a3e2c85 commit d48c443

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

scripts/threading_enum.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
import random
3+
import threading
4+
import time
5+
import logging
6+
7+
8+
def worker():
9+
"""thread worker function"""
10+
pause = random.randint(1, 5) / 10
11+
logging.debug('sleeping %0.2f', pause)
12+
time.sleep(pause)
13+
logging.debug('ending')
14+
15+
16+
logging.basicConfig(
17+
level=logging.DEBUG,
18+
format='(%(threadName)-10s) %(message)s',
19+
)
20+
21+
for i in range(3):
22+
t = threading.Thread(target=worker, daemon=True)
23+
t.start()
24+
25+
main_thread = threading.main_thread()
26+
for t in threading.enumerate():
27+
if t is main_thread:
28+
continue
29+
logging.debug('joining %s', t.getName())
30+
t.join()
31+

0 commit comments

Comments
 (0)