I'm trying to implement a python script that can send serial data generated by two different threads. Now I was able to set the threads running, I would like to create a shared memory with semaphores between the manager process and the sub threads. The code of the manager is the following
import DetectorService
import HearingService
if __name__=='__main__':
global shm01
t1 = Thread(target = DetectorService.start)
t2 = Thread(target = HearingService.start)
t1.setDaemon(True)
t2.setDaemon(True)
t1.start()
t2.start()
while True:
# Get data from thread01
# Get data from thread02
# Send data via serial port
pass
Then there is a minimal representation of a thread:
import time
def start():
while True:
a = a + 1
time.sleep(0.5)
For instance, my goal is to access the a
variable and send the value through the serial port. The serial communication is not a problem, I know how to do it.
So my question is, how can I implement the shared memory?