Any documentation about Python daemons?
Erik de Castro Lopo
erikd at zip.com.au
Sat Mar 3 05:55:23 EST 2001
gradha at iname.com wrote:
>
> Hello.
>
> I would like to write now a program which acts as a server on the same
> machine for other clients in a Linux environment, something in the spirit
> of chronyd, if you know the program.
Sorry, i don't.
> However, I am new both to Python and process' intercommunication. Could
> you suggest me ways of doing this and/or point me to documentation
> explaining such communication methods? I first thought about nice pipes,
> but then I realized that the server program should be running always, not
> being allowed to fork, and clients could mantain multiple communication
> channels at the same time (ej: daemon + 2 clients). How could I do this?
This sounds like a job for sockets. The Python documentation has a very
good section on the sockets module which I found pretty easy to follow.
There is also a more advanced module called SocketServer but I haven't
used that.
As for having multiple clients connect to one server you have a number
of options:
- fork - only really of much use if the different server
processes do not need to share very much data
- threads - this overcomes the data sharing problems of
forking but you will need to use locking to protect
shared data.
- one process which uses select to manipulate multiple
input and output connections
My application was a Tk based logging daemon which displays the
output of a number of clients graphically. Because the clients
all had to plot to the same Tk widgets I chode the multi-threaded
model. I managed to get something working from scratch in about
10 hours spread over three days.
Hope this helps,
Erik
--
-----------------------------------------------------------------
Erik de Castro Lopo nospam at mega-nerd.com (Yes its valid)
-----------------------------------------------------------------
"I think there is a world market for maybe five computers."
-- Thomas Watson, Chairman of IBM, 1943
More information about the Python-list
mailing list