passing data to a daemon

Discussion in 'Python' started by Rob Hunter, Oct 4, 2003.

  1. Rob Hunter

    Rob Hunter Guest

    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
     
    Rob Hunter, Oct 4, 2003
    #1
    1. Advertising

  2. Rob Hunter

    Eugene Oden Guest

    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

    Rob Hunter wrote:

    > 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
     
    Eugene Oden, Oct 5, 2003
    #2
    1. Advertising

  3. In article <>, Rob Hunter wrote:
    > 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.
     
    =?iso-8859-1?Q?Nils_O=2E_Sel=E5sdal?=, Oct 5, 2003
    #3
  4. Rob Hunter wrote:
    > 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
     
    Irmen de Jong, Oct 5, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Stevens

    Forking HTTP Daemon - Problem

    Matt Stevens, Dec 8, 2003, in forum: Perl
    Replies:
    1
    Views:
    674
    Jim Gibson
    Dec 9, 2003
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    463
    Jean-Paul Calderone
    Mar 20, 2009
  3. Floris Bruynooghe
    Replies:
    1
    Views:
    455
    Floris Bruynooghe
    Mar 24, 2009
  4. MacRules
    Replies:
    9
    Views:
    829
    Dennis Lee Bieber
    Sep 5, 2009
  5. Daemon Win32::Daemon;

    , Sep 7, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    259
Loading...

Share This Page