MCPcopy
hub / github.com/celery/celery / _boundmethod_safe_weakref

Function _boundmethod_safe_weakref

celery/utils/dispatch/signal.py:32–51  ·  view source on GitHub ↗

Get weakref constructor appropriate for `obj`. `obj` may be a bound method. Bound method objects must be special-cased because they're usually garbage collected immediately, even if the instance they're bound to persists. Returns: a (weakref constructor, main object) tuple. `w

(obj)

Source from the content-addressed store, hash-verified

30
31
32def _boundmethod_safe_weakref(obj):
33 """Get weakref constructor appropriate for `obj`. `obj` may be a bound method.
34
35 Bound method objects must be special-cased because they're usually garbage
36 collected immediately, even if the instance they're bound to persists.
37
38 Returns:
39 a (weakref constructor, main object) tuple. `weakref constructor` is
40 either :class:`weakref.ref` or :class:`weakref.WeakMethod`. `main
41 object` is the instance that `obj` is bound to if it is a bound method;
42 otherwise `main object` is simply `obj.
43 """
44 try:
45 obj.__func__
46 obj.__self__
47 # Bound method
48 return WeakMethod, obj.__self__
49 except AttributeError:
50 # Not a bound method
51 return weakref.ref, obj
52
53
54def _make_lookup_key(receiver, sender, dispatch_uid):

Callers 1

_connect_signalMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected