[Calypso] [PATCH] Only import lockfile.pidlockfile when needed
Guido Günther
agx at sigxcpu.org
Tue Jan 26 09:29:35 PST 2016
On Mon, Jan 25, 2016 at 10:40:13PM +0100, Petter Reinholdtsen wrote:
>
> [Petter Reinholdtsen]
> > Perhaps fail gracefully to use daemon.pidlockfile if lockfile do not
> > have pidlockfile? It would allow it to work with older
> > python-lockfile versions too?
>
> I had something like this in mind:
>
> diff --git a/calypso.py b/calypso.py
> index c3c1999..000d88d 100755
> --- a/calypso.py
> +++ b/calypso.py
> @@ -38,7 +38,6 @@ arguments.
>
> import daemon
> import lockfile
> -from lockfile import pidlockfile
> import logging
> import optparse
> import os
> @@ -149,6 +148,10 @@ if not options.daemon:
> context = daemon.DaemonContext()
> context.umask = 0o002
> if options.pidfile:
> + try:
> + from lockfile import pidlockfile
> + except ImportError:
> + from daemon import pidlockfile
> # Generate a pidfile where requested
> context.pidfile = pidlockfile.PIDLockFile(options.pidfile)
> with context:
>
> But when I test it in Jessie without pidlockfile in lockfile, I get this
> error, which I do not understand:
>
> % ./calypso.py -g --pid-file=/tmp/foo -d
> enable debugging
> Traceback (most recent call last):
> File "./calypso.py", line 154, in <module>
> from daemon import pidlockfile
> File "/usr/lib/pymodules/python2.7/daemon/pidlockfile.py", line 33, in <module>
> class PIDLockFile(LinkFileLock, object):
> TypeError: Error when calling the metaclass bases
> function() argument 1 must be code, not str
> %
>
> Note, there is a usability problem with the current pidfile handling.
> When using --daemon as a normal user and the pidfile configuration point
> to a unwritable location, the daemon dies without any messages and
> without any trace about what went wrong. I had to strace the process to
> figure out what went wrong... :)
Since there seems to be a problem with this one I went ahead and pushed
the previous version to allow to test on Jessie.
Cheers,
-- Guido
More information about the Calypso
mailing list