passing data to a daemon

R

Rob Hunter

Hi all.

I want to run a Python daemon that manages a "to-do" queue. I want it
so that the daemon is always running, where its running consists of
looking at the queue to see if it has any jobs, and if it does, remove
the job from the queue and "do the job".

This all seems quite doable using the synchronized Queue.py module and
this page
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012) which
describes writing a daemon in Python.

My problem is: how will I submit jobs to the queue? The issue is that
jobs are generated by users of, say, the operating system, so they
aren't a part of the daemon process. Ideally, I want a way of making a
function call to the daemon process *from outside the daemon process*.

For example, say my daemon has the function in it "addToQueue". I'd
like to write a totally separate piece of Python code that calls this
function inside the *running* daemon.

I suppose I could use files with locking as an interface, but there's
got to be a better way.

Thanks for any tips,

Rob
 
E

Eugene Oden

there are a number of ways you could do this, ranging from sending a message
to the daemon over a socket (probably using the select() function) or using
a higher layer remote method invocation or object broker library. the
twisted project (http://www.twistedmatrix.com/) seems to provide some
useful utilities for this. others you might consider are zope
(http://www.zope.org) or pyro (http://pyro.sourceforge.net). i don't have
much experience with any of these but hopefully you'll find something
useful.

later,

gene
 
?

=?iso-8859-1?Q?Nils_O=2E_Sel=E5sdal?=

Hi all.

I want to run a Python daemon that manages a "to-do" queue. I want it
so that the daemon is always running, where its running consists of
looking at the queue to see if it has any jobs, and if it does, remove
the job from the queue and "do the job".

This all seems quite doable using the synchronized Queue.py module and
this page
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012) which
describes writing a daemon in Python.

My problem is: how will I submit jobs to the queue? The issue is that
jobs are generated by users of, say, the operating system, so they
aren't a part of the daemon process. Ideally, I want a way of making a
function call to the daemon process *from outside the daemon process*.

For example, say my daemon has the function in it "addToQueue". I'd
like to write a totally separate piece of Python code that calls this
function inside the *running* daemon.

I suppose I could use files with locking as an interface, but there's
got to be a better way.
Files are one way. Sockets another. Make it listen on a socket
and accept commands from it, write a client that connects
to and send commands/data to it. If you're on *nix, use
unix sockets. Higher level API's over sockets can also be used,
e.g. xml-rpc or corba.
 
I

Irmen de Jong

Rob said:
My problem is: how will I submit jobs to the queue? The issue is that
jobs are generated by users of, say, the operating system, so they
aren't a part of the daemon process. Ideally, I want a way of making a
function call to the daemon process *from outside the daemon process*.

For example, say my daemon has the function in it "addToQueue". I'd
like to write a totally separate piece of Python code that calls this
function inside the *running* daemon.

Use Pyro (http://pyro.sourceforge.net)
With only a few (3 to 4) extra lines in your code you're able
to call methods in different Python processes just as if
it was a 'local' method. No network programming needed at all.

Good luck
--Irmen de Jong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top