I want to build a script that can be controlled while running from another scripts. For example I want to run my script like this:
~: Server &
and be able to run one of it's functions like:
~: client func1
Upon my searches I find signal module that have something like I want, but it's signals are predefined and I can not send signals of my own.
I even though of a client/server implementation using a network framework but I think it's too much for the abilities that I want my script to have.
Thank you all.
So you need to talk to a running process right? What about the idea of unix domain socket?
In your server you can build up a socket on a path of your unix file system, then talk to that socket in you client, like described in this link I googled:
http://pymotw.com/2/socket/uds.html
If you are only trying to send commands one-directionally to a server, it is easier than you think, using Python's Sockets. The code samples are of course barebones in the sense that they do not do error handling, and do not call
recv
multiple times to make sure the message is complete. This is just to give you an idea of how few lines of code it takes to process commands.Here is a server program that simply receives messages and prints to
stdout
. Note that we use threading so that the server can listen to multiple clients at once.Here is a client program that sends commands to it.