Hello guys, thank your for reading.
Well, I have a single python process which is using a serial port (unique resource) which is manage using an instance of a (A=Class A). Exist two different thread initialized using B=Class_B() and C=Class_C(), which are constantly using the serial port resource through the objected already created called.
Class A(threading.Thread):
#Zigbee serial port handler
def __init__(self,dev):
#something here that initialize serial port
def run():
while True:
#listening serial interface
def pack(self):
#something
def checksum(self):
#something
def write(self):
#something
Class B(threading.Thread):
def __init__(self,SerialPortHandler):
self.serialporthandler=SerialPortHandler
def run(self)
while True:
#something that uses self.serialporthandler
Class C(threading.Thread):
def __init__(self,SerialPortHandler):
self.serialporthandler=SerialPortHandler
def run(self)
while True:
#something that uses self.serialporthandler
def main():
a=A('/dev/ttyUSB1')
b=B(a)
b.start()
c=C(a)
c.start()
if __name__=='main':
while True:
main()
The problem is obvious, and is that both thread are trying to access the serial resource at the same time. I could use several instances of the same Class A, attaching Lock.acquire() and Lock.release() in the sensitive parts, but the
Could some of you point me to the right way?
thank you in advance