6

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.

8
  • Of course you can, at least on Unix platforms, but you'll have to use some kind of synchronization mechanism between the processes.
    – Fred Foo
    Commented Jan 5, 2012 at 16:27
  • Why would I need synchronization mechanisms? The serial port is full duplex, right? Commented Jan 5, 2012 at 16:31
  • Ah, you mean one process reads and one writes? That shouldn't be a problem, I guess. (Not a serial comms expert, though.)
    – Fred Foo
    Commented Jan 5, 2012 at 16:33
  • 2
    Full duplex mean input/output communication can be done together. That's doesn't mean multiple process can use it at the same time. A serial port can be attached only one, only one client can take the port and talk at time.
    – tito
    Commented Jan 5, 2012 at 16:35
  • Yep. I want one process to write, and another process to read. I will use a queueing mechanism to interact with another process that is actually making sure that the synchronization of the actual protocol is correct. Commented Jan 5, 2012 at 16:35

1 Answer 1

4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.