-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread_test.py
More file actions
30 lines (25 loc) · 870 Bytes
/
thread_test.py
File metadata and controls
30 lines (25 loc) · 870 Bytes
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
import logging
import threading
import time
class ThreadEx():
def init(self):
self.name = 'mythread'
def thread_function(self, name):
logging.info("Thread %s: starting", self.name)
time.sleep(2)
logging.info("Thread %s: finishing", name)
def start_test(self):
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO,
datefmt="%H:%M:%S")
logging.info("Main : before creating thread")
x = threading.Thread(target=self.thread_function, args=(1,))
logging.info("Main : before running thread")
x.start()
logging.info("Main : wait for the thread to finish")
# x.join()
logging.info("Main : all done")
if __name__ == "__main__":
te = ThreadEx()
te.init()
te.start_test()