问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/8745948/how-can-you-access-a-serial-port-from-two-different-processes-python