0

I am developing a data monitor using PyQt5. I need to read from multiple sensors through serial ports. One or two of the sensors require different commands to send and then read the data, while the rest send data at a fixed speed.

How can I monitor multiple ports without interrupting the UI? I don't know if I should use QThread, threading, multiprocessing, subprocesses, or any other technique. I'm not trying to ask an opinionated question, and if these all "work," then what are the relevant pros and cons of each technique?

I am really struggling to find information on what I am doing. It is very frustrating, as my problem seems so simple, but I can't find any relevant projects, examples, or tutorials. A point in the right direction would be great.

Gabe G
  • 1

1 Answers1

0

Just as a real rough description:

threading maintains the same memory space as your main thread. This means that you can reference certain variables between threads.

Qthread is similar to normal threading, but it also includes the ability to restart the thread and can use slots/signals. If you're using PyQt5, I would use this over the normal threading library if possible.

multiprocessing does not use the same memory space. So it'll have to create a copy of any variables needed for the multiprocess and then it's completely independent. You can use a multiprocess queue to pass information between multiprocesses though.

subprocess lets you control other programs. It's used to integrate external programs into your project.

Here's a link to another similar question to yours: deciding among subprocess, multiprocessing, and thread in Python?

If you want someone to just tell you one to use, I would start with QThread so you can still reference that data easily and it plays well with PyQt5 architecture in general. You can also see if QSerial itself will not disrupt the UI as suggested by musicamante.

Andew
  • 321
  • 1
  • 9
  • Thank you. This was extremely helpful. Concerning your comment about QSerialPort, I can't seem to find documentation on it in PyQt5, only Qt5 in C++. Where would I find more information or examples on QSerialPort in Python? Does much change at all in its implementation? I think this may be what I want to use, I just can't seem to find out how to use it. – Gabe G Nov 09 '22 at 22:09
  • You may need to convert the C++ to python. If not look up examples and tutorials. – Andew Nov 10 '22 at 12:29
  • This seems to be a blog with some examples: https://ymt-lab.com/en/post/2021/pyqt5-serial-monitor/ – Andew Nov 10 '22 at 12:33