问题
I am looking to have a MML (man machine language) console written in Python as the only entry point to control and monitor a back-end process. Basically will be able to:
- attach to an existing back-end process
- if back-end process is not running, still open console and be able to spawn back-end process (by introducing the correct command)
- auto-complete permitted commands
- be able to change back-end process behavior based on the introduced commands
What would be the best way to achieve this? How to communicate the back-end process with a console that can be opened and closed without killing the back-end process, by this I mean that the console would not be the parent of that process.
Needs to be written in Python and will run on a CentOS, maybe some OS tools can help to communicate processes?
回答1:
High on my list would be twisted. It's fairly easy to build a an interactive console with and it's Perspective Broker system would probably work well for you. Plus it's very robust, has a fast event loop, and it's very robust.
You could also use the cmd module, which was recently featured on Doug Hellmann's excellent site Python Module of the Week (PyMOTW).
For interprocess communication, ZeroMQ is fairly easy to work with, and it's very fast.
回答2:
Maybe this is a start: http://code.google.com/p/squires/wiki/SquiresHowto
You could use a Socket to do the communication between Front- and Backend.
来源:https://stackoverflow.com/questions/5917834/basics-to-create-a-mml-console-in-python