This document describes the current stable version of Celery (5.7). For development docs, go here.
celery.utils.threads¶
Threading primitives and utilities.
- class celery.utils.threads.LocalManager(locals=None, ident_func=None)[source]¶
Local objects cannot manage themselves.
For that you need a local manager. You can pass a local manager multiple locals or add them later by appending them to
manager.locals. Every time the manager cleans up, it will clean up all the data left in the locals for this context.The
ident_funcparameter can be added to override the default ident function for the wrapped locals.
- celery.utils.threads.LocalStack¶
alias of
_LocalStack
- class celery.utils.threads.bgThread(name=None, **kwargs)[source]¶
Background service thread.
- run()[source]¶
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- celery.utils.threads.bound_open_broker_sockets(connection, timeout)[source]¶
Apply
timeoutto broker sockets that are already connected.socket.setdefaulttimeout()only affects sockets created afterwards, so neither it norConnection.collect(socket_timeout=...)can bound a read on a socket that is already open. Teardown issues exactly such reads (the redis transport drains a pendingBRPOPinChannel.close(), py-amqp waits for abasic_cancelreply), and against a peer that went silent without RST they never return.See Issue #9705 (reconnect) and Issue #975 (shutdown). Best effort: never raises, as both callers are teardown paths.
- celery.utils.threads.default_socket_timeout(timeout)[source]¶
Context temporarily setting the default socket timeout.
Note
Only affects sockets created afterwards. To bound a connection that is already open, use
bound_open_broker_sockets().
- celery.utils.threads.get_ident()¶
getcurrent() -> greenlet
Returns the current greenlet (i.e. the one which called this function).