I am not an expert on this issue, but I still think that the number of additional subtleties using threading is not worth the effort if I can parallelize through processes.
The third module that you did not mention among the alternatives is subprocess .
EDIT on request OP:. You can do parallel processing by creating separate scripts for serial interfaces. This is a quick demo, assuming both files are in the same directory.
The com.py file - a serial script - is just a layout, but the idea here is that the script works autonomously and uses only stdin and stdout to communicate with the master program.
import sys counter = 0 while True:
master.py file - the main program
from subprocess import Popen, PIPE from time import sleep p = Popen(['python', './com.py'], stdin=PIPE, stdout=PIPE, stderr=PIPE) print "serial communication started."
Finally, this is a dump of the expected result:
mac@jabbar :~/Desktop$ ./master.py serial communication started. comand sent. received : Serial from com1 is 1 comand sent. received : Serial from com1 is 2 comand sent. received : Serial from com1 is 3
NTN!
source share