How read two or more serial ports in parallel with Python

Hi everyone,

I am trying to read two (or more) serial ports with Python-QT but without success.
I am able to read and display the values received (baud rate 9600) from one serial port, but when I try with two python crashes. I have tried to use also two separate threads but it does not work.
(My computer is able to read the two serial ports using two Terminal threads)

Is it a limitation of Python or there is a solution?

Can someone help me with that?

Thank you.
Best regards,

Without seeing the details it’s hard to say if that is the problem, but in CPython threads can’t execute Python code in parallel as the documentation of the threading module describes, and it lists alternatives:

In CPython, due to the Global Interpreter Lock, only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome this limitation). If you want your application to make better use of the computational resources of multi-core machines, you are advised to use multiprocessing or concurrent.futures.ProcessPoolExecutor .

Both multiprocessing and the ProcessPoolExecutor can distribute the work over multiple processes, which can then run Python code in parallel.

I hope this helps!

1 Like

Thank you very much. I will try these solutions.

1 Like