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

老子叫甜甜 提交于 2019-12-20 02:13:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!