-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestThreading.py
32 lines (28 loc) · 915 Bytes
/
testThreading.py
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
import logging
import threading
import time
import serial
def thread_function(name, y):
logging.info("Thread %s: starting", y)
for i in range(10):
ser.write(b'0')
time.sleep(0.1)
ser.write(b'1')
time.sleep(0.1)
logging.info("Thread %s: finishing", y)
if __name__ == "__main__":
y = [1]
ser = serial.Serial('/dev/ttyACM0', 115200)
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO,
datefmt="%H:%M:%S")
logging.info("Main : before creating thread")
for i in range(2):
x = threading.Thread(target=thread_function, args=(1,y), daemon=True)
logging.info("Main : before running thread")
x.start()
time.sleep(5)
y = [2]
logging.info("Main : wait for the thread to finish")
x.join()
logging.info("Main : all done")