We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a3e2c85 commit d48c443Copy full SHA for d48c443
scripts/threading_enum.py
@@ -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