celery.platforms

Platforms.

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

class celery.platforms.DaemonContext(pidfile=None, workdir=None, umask=None, fake=False, after_chdir=None, after_forkers=True, **kwargs)[исходный код]

Context manager daemonizing the process.

close(*args)[исходный код]
open()[исходный код]
redirect_to_null(fd)[исходный код]
exception celery.platforms.LockFailed[исходный код]

Raised if a PID lock can’t be acquired.

class celery.platforms.Pidfile(path)[исходный код]

Pidfile.

This is the type returned by create_pidlock().

См.также

Best practice is to not use this directly but rather use the create_pidlock() function instead: more convenient and also removes stale pidfiles (when the process holding the lock is no longer running).

acquire()[исходный код]

Acquire lock.

is_locked()[исходный код]

Return true if the pid lock exists.

path = None

Path to the pid lock file.

read_pid()[исходный код]

Read and return the current pid.

release(*args)[исходный код]

Release lock.

remove()[исходный код]

Remove the lock.

remove_if_stale()[исходный код]

Remove the lock if the process isn’t running.

I.e. process does not respond to signal.

write_pid()[исходный код]
celery.platforms.close_open_fds(keep=None)[исходный код]
celery.platforms.create_pidlock(pidfile)[исходный код]

Create and verify pidfile.

If the pidfile already exists the program exits with an error message, however if the process it refers to isn’t running anymore, the pidfile is deleted and the program continues.

This function will automatically install an atexit handler to release the lock at exit, you can skip this by calling _create_pidlock() instead.

Результат:

used to manage the lock.

Тип результата:

Pidfile

Пример

>>> pidlock = create_pidlock('/var/run/app.pid')
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).

Параметры:
  • logfile (str) – Optional log file. The ability to write to this file will be verified before the process is detached.

  • pidfile (str) – Optional pid file. The pidfile won’t 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 (int, str) – Optional user id or user name to change effective privileges to.

  • gid (int, str) – Optional group id or group name to change effective privileges to.

  • umask (str, int) – Optional umask that’ll be effective in the child process.

  • workdir (str) – Optional new working directory.

  • fake (bool) – Don’t actually detach, intended for debugging purposes.

  • **opts (Any) – Ignored.

Пример

>>> 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 isn't locked.
... pidlock = create_pidlock('/var/run/app.pid')
...
... # Run the program
... program.run(logfile='/var/log/app.log')
celery.platforms.fd_by_path(paths)[исходный код]

Return a list of file descriptors.

This method returns list of file descriptors corresponding to file paths passed in paths variable.

Параметры:

paths – List[str]: List of file paths.

Результат:

List of file descriptors.

Тип результата:

List[int]

Пример

>>> keep = fd_by_path(['/dev/urandom', '/my/precious/'])
celery.platforms.get_errno_name(n)[исходный код]

Get errno for string (e.g., ENOENT).

celery.platforms.get_fdmax(default=None)[исходный код]

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

Именованные аргументы:

default – Value returned if there’s no file descriptor limit.

celery.platforms.ignore_errno(*errnos, **kwargs)[исходный код]

Context manager to ignore specific POSIX error codes.

Takes a list of error codes to ignore: this can be either the name of the code, or the code integer itself:

>>> with ignore_errno('ENOENT'):
...     with open('foo', 'r') as fh:
...         return fh.read()

>>> with ignore_errno(errno.ENOENT, errno.EPERM):
...    pass
Параметры:

types (Tuple[Exception]) – A tuple of exceptions to ignore (when the errno matches). Defaults to Exception.

celery.platforms.initgroups(uid, gid)[исходный код]

Init process group permissions.

Compat version of os.initgroups() that was first added to Python 2.7.

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 (str, int) – Actual gid, or the name of a group.

Результат:

The actual gid of the group.

Тип результата:

int

celery.platforms.parse_uid(uid)[исходный код]

Parse user id.

Параметры:

uid (str, int) – Actual uid, or the username of a user.

Результат:

The actual uid.

Тип результата:

int

celery.platforms.pyimplementation()[исходный код]

Return string identifying the current Python implementation.

celery.platforms.set_mp_process_title(progname, info=None, hostname=None)[исходный код]

Set the ps name from the current 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.setgid(gid)[исходный код]

Version of os.setgid() supporting group names.

celery.platforms.setgroups(groups)[исходный код]

Set active groups from a list of group ids.

celery.platforms.setuid(uid)[исходный код]

Version of os.setuid() supporting usernames.

celery.platforms.signal_name(signum)[исходный код]

Return name of signal from signal number.

Вернуться на верх