This document describes an older version of Celery (2.5). For the latest stable version please go here.
Utilities dealing with platform specifics: signals, daemonization, users, groups, and so on.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
Raised if a pidlock can’t be acquired.
PID lock file.
This is the type returned by create_pidlock().
Should not be used directly, use the :func:`create_pidlock` context instead
Acquire lock.
Returns true if the pid lock exists.
Path to the pid lock file.
Reads and returns the current pid.
Release lock.
Removes the lock.
Removes the lock if the process is not running. (does not respond to 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)
Ignore signal using SIG_IGN.
Does nothing if the platform doesn’t support signals, or the specified signal in particular.
Reset signals to the default signal handler.
Does nothing if the platform doesn’t support signals, or the specified signal in particular.
Get signal number from signal name.
Returns true value if signal_name exists on this platform.
Set signal handlers from a mapping.
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)
Detach the current process in the background (daemonize).
Parameters: |
|
---|
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")
Returns the maximum number of open file descriptors on this system.
Parameters: | default – Value returned if there’s no file descriptor limit. |
---|
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.
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.
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.
Set the ps name using the multiprocessing process name.
Only works if setproctitle is installed.
Set the ps name for the currently running process.
Only works if setproctitle is installed.
Set effective group id.
Set effective user id.