This document describes the current stable version of Celery (4.0). For development docs, go here.

celery.utils.dispatch.saferef

Safe weakrefs, originally from pyDispatcher.

Provides a way to safely weakref any function, including bound methods (which aren’t handled by the core weakref module).

celery.utils.dispatch.saferef.safe_ref(target, on_delete=None)[source]

Return a safe weak reference to a callable target.

Parameters:
  • target (Any) – The object to be weakly referenced, if it’s a bound method reference, will create a BoundMethodWeakref, otherwise creates a simple weakref.ref.
  • on_delete (Callable) – If provided, will have a hard reference stored to the callable to be called after the safe reference goes out of scope with the reference object, (either a weakref.ref or a BoundMethodWeakref) as argument.