-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_thread.py
More file actions
50 lines (31 loc) · 1 KB
/
1_thread.py
File metadata and controls
50 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Topic: Thread
Keyword: Main Thread, Child Thread, Daemon Thread, Thread.join()
"""
import threading
import time
import logging
def test_thread_func(name, n):
logging.info("%s-Thread : started", name)
for i in range(n):
print(name, i, "\n", end="")
logging.info("%s-Thread : done", name)
def main():
log_format = "%(asctime)s: %(message)s"
logging.basicConfig(format=log_format,
level=logging.INFO, datefmt="%H:%M:%S")
logging.info("Main-Thread starts")
logging.info("Creates Child-Threads")
child_thread = threading.Thread(
target=test_thread_func, args=("Child", 5000000,))
daemon_thread = threading.Thread(
target=test_thread_func, args=("Daemon", 5000000,), daemon=False)
# Starts Created Thread
child_thread.start()
daemon_thread.start()
# Stop Main Thread until the Child Threads finish
# child_thread.join()
# daemon_thread.join()
logging.info("Main-Thread done")
if __name__ == "__main__":
main()