Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you access a serial port from two different processes (Python)

I would like to use multiprocessing (to avoid GIL issues on multi core machines) and have a read process and a write process using the same serial port. Is that possible? If so, how do I get the port acquired and then how do I get the child processes file objects that they can use?

Edit -- This needs to work on Windows, but Mac and Linux would also be nice.

like image 432
K. Brafford Avatar asked Oct 09 '22 01:10

K. Brafford


1 Answers

As stated in the comments, only one process can acquire the serial port at a time - therefore the way to go is to create yet another process, possibly using Python xmlrpc, or jsonrpc, that will do the actual hardware I/O, and modify your current read and write scripts to call remote functions on that other process.

The example in the library documentation should be enough for implementing such "I/O server process" with xmlrpc: http://docs.python.org/library/simplexmlrpcserver.html

like image 102
jsbueno Avatar answered Oct 13 '22 00:10

jsbueno