I have a problem with multiprocessing. If I am waiting for input in a thread the process is not starting.
The class to put the input into a queue in the background:
class InputCatcher(Thread):
def __init__(self, input_queue):
Thread.__init__(self)
self.input_queue = input_queue
def run(self):
while True:
self.input_queue.put(input()) # <<-- Without this it works!
The class that will not start:
class Usb(Process):
def __init__(self, port, ctrl=Controller()):
Process.__init__(self)
self.usb_port = port
self.ctrl = ctrl
def run(self):
self.ctrl.usb_ports.append(self.usb_port)
ser = Serial(self.usb_port, 115200)
while True:
dsl = ser.readline()
self.ctrl.get_dataset_queue().put(['USBDS', dsl])
print(dsl)
Starting with:
ic = InputCatcher(self.input_queue)
ic.setDaemon(True)
ic.start()
usbs = []
for port in usb_ports():
if not port in ctrl.xbee_ports:
usbs.append(Usb(port, ctrl))
for usb in usbs:
usb.daemon = True
usb.start()