"Daemonizing" an application.

Sven svenito at gmail.com
Wed Feb 27 06:15:28 EST 2013


On 27 February 2013 11:03, Chris Angelico <rosuav at gmail.com> wrote:

> On Wed, Feb 27, 2013 at 9:52 PM, Gilles Lenfant
> <gilles.lenfant at gmail.com> wrote:
> > Hello,
> >
> > Sorry for the obscure title, but I can't make short to explain what I'm
> searching for. :)
> >
> > I made an app (kind of proxy) that works without UI within it's process.
> So far, so good.
> >
> > Now I need to change "live" some controls of this application, without
> stopping it.
> >
> > So my app will be split in two :
> >
> > * A control app (say "appctl") for a console UI
> > * A daemon (or agent ?) that runs the core of the app (say "appd"),
> processing inputs and outputs
>
> Daemonizing is a fairly specific operation (forking and disconnecting
> from the console), which may well be a part of what you're asking for,
> but on the other hand may be unnecessary (if, for instance, you let
> your core app be invoked by Upstart directly).
>
> What form of control do you need? With many apps of this nature, the
> only control required is Unix signals - particularly SIGHUP, to say
> "I've edited your config files, go reread them". Your front end might
> do the editing, or you could even abolish the control app altogether
> and simply edit the configs manually. But if you need more, you'll
> need to work out how you want them to communicate with each other.
>
> What platform or platforms do you need this to run on?
>
> Regardless of your answers to the above, I would say that in all
> probability *yes*, you will be able to do this with just Python and
> the standard library. There are a lot of batteries included with
> Python :)
>

One solution is to use XMLRPC to communicate with the daemonized process.
This does involve the daemon listening on the local network. The GUI can
then connect to the daemon and send it commands which essentially is
calling functions on the daemon. These can then change certain behaviors of
the daemon process without restarting it. If you want to be hardcore you
can use sockets. There are other networking libs like Twisted and RabbitMQ,
but they might be a bit overkill for your purpose.

But whether any of this is ok depends on your use case. The signals Chris
mentioned will also work. Alternatively there are a number of filewatching
libraries like watchdog or https://github.com/seb-m/pyinotify which you can
use to monitor changes to a config file if that's the way you want to go.

-- 
./Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130227/945def83/attachment.html>


More information about the Python-list mailing list