This document describes an older version of Celery (2.5). For the latest stable version please go here.

celery.platforms

celery.platforms

Utilities dealing with platform specifics: signals, daemonization, users, groups, and so on.

copyright:
  1. 2009 - 2012 by Ask Solem.
license:

BSD, see LICENSE for more details.

class celery.platforms.DaemonContext(pidfile=None, workdir=None, umask=None, fake=False, **kwargs)
close(*args)
open()
umask = 0
workdir = '/'
exception celery.platforms.LockFailed

Raised if a pidlock can’t be acquired.

class celery.platforms.PIDFile(path)

PID lock file.

This is the type returned by create_pidlock().

Should not be used directly, use the :func:`create_pidlock` context instead

acquire()

Acquire lock.

is_locked()

Returns true if the pid lock exists.

path = None

Path to the pid lock file.

read_pid()

Reads and returns the current pid.

release(*args)

Release lock.

remove()

Removes the lock.

remove_if_stale()

Removes the lock if the process is not running. (does not respond to signals).

write_pid()
class celery.platforms.Signals

Convenience interface to signals.

If the requested signal is not supported on the current platform, the operation will be ignored.

Examples:

>>> from celery.platforms import signals

>>> signals["INT"] = my_handler

>>> signals["INT"]
my_handler

>>> signals.supported("INT")
True

>>> signals.signum("INT")
2

>>> signals.ignore("USR1")
>>> signals["USR1"] == signals.ignored
True

>>> signals.reset("USR1")
>>> signals["USR1"] == signals.default
True

>>> signals.update(INT=exit_handler,
...                TERM=exit_handler,
...                HUP=hup_handler)
default = 0
ignore(*signal_names)

Ignore signal using SIG_IGN.

Does nothing if the platform doesn’t support signals, or the specified signal in particular.

ignored = 1
reset(*signal_names)

Reset signals to the default signal handler.

Does nothing if the platform doesn’t support signals, or the specified signal in particular.

signum(signal_name)

Get signal number from signal name.

supported(signal_name)

Returns true value if signal_name exists on this platform.

update(_d_=None, **sigmap)

Set signal handlers from a mapping.

celery.platforms.create_pidlock(pidfile)

Create and verify pid file.

If the pid file already exists the program exits with an error message, however if the process it refers to is not running anymore, the pid file is deleted and the program continues.

The caller is responsible for releasing the lock before the program exits.

Returns:PIDFile.

Example:

import atexit
pidlock = create_pidlock("/var/run/app.pid").acquire()
atexit.register(pidlock.release)
celery.platforms.detached(logfile=None, pidfile=None, uid=None, gid=None, umask=0, workdir=None, fake=False, **opts)

Detach the current process in the background (daemonize).

Parameters:
  • logfile – Optional log file. The ability to write to this file will be verified before the process is detached.
  • pidfile – Optional pid file. The pid file will not be created, as this is the responsibility of the child. But the process will exit if the pid lock exists and the pid written is still running.
  • uid – Optional user id or user name to change effective privileges to.
  • gid – Optional group id or group name to change effective privileges to.
  • umask – Optional umask that will be effective in the child process.
  • workdir – Optional new working directory.
  • fake – Don’t actually detach, intented for debugging purposes.
  • **opts – Ignored.

Example:

import atexit
from celery.platforms import detached, create_pidlock

with detached(logfile="/var/log/app.log", pidfile="/var/run/app.pid",
              uid="nobody"):
    # Now in detached child process with effective user set to nobody,
    # and we know that our logfile can be written to, and that
    # the pidfile is not locked.
    pidlock = create_pidlock("/var/run/app.pid").acquire()
    atexit.register(pidlock.release)

    # Run the program
    program.run(logfile="/var/log/app.log")
celery.platforms.get_fdmax(default=None)

Returns the maximum number of open file descriptors on this system.

Parameters:default – Value returned if there’s no file descriptor limit.
celery.platforms.initgroups(uid, gid)
celery.platforms.maybe_drop_privileges(uid=None, gid=None)

Change process privileges to new user/group.

If UID and GID is specified, the real user/group is changed.

If only UID is specified, the real user is changed, and the group is changed to the users primary group.

If only GID is specified, only the group is changed.

celery.platforms.parse_gid(gid)

Parse group id.

gid can be an integer (gid) or a string (group name), if a group name the gid is taken from the password file.

celery.platforms.parse_uid(uid)

Parse user id.

uid can be an integer (uid) or a string (user name), if a user name the uid is taken from the password file.

celery.platforms.pyimplementation()
celery.platforms.set_mp_process_title(progname, info=None, hostname=None, rate_limit=False)

Set the ps name using the multiprocessing process name.

Only works if setproctitle is installed.

celery.platforms.set_process_title(progname, info=None)

Set the ps name for the currently running process.

Only works if setproctitle is installed.

celery.platforms.setegid(gid)

Set effective group id.

celery.platforms.seteuid(uid)

Set effective user id.

celery.platforms.setgid(gid)
celery.platforms.setgroups(groups)
celery.platforms.setuid(uid)
celery.platforms.shellsplit(s, posix=True)
celery.platforms.strargv(argv)

Previous topic

celery.utils.dispatch.saferef

This Page