| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from weakref import WeakSet |
| 5 |
|
| 6 |
|
| 7 |
__all__ = [ |
| 8 |
'aio', |
| 9 |
'auth', |
| 10 |
'aws_iot_metrics', |
| 11 |
'crypto', |
| 12 |
'http', |
| 13 |
'io', |
| 14 |
'logging', |
| 15 |
'mqtt', |
| 16 |
'mqtt5', |
| 17 |
'mqtt_request_response', |
| 18 |
's3', |
| 19 |
'websocket', |
| 20 |
] |
| 21 |
|
| 22 |
__version__ = '1.0.0.dev0' |
| 23 |
|
| 24 |
|
| 25 |
class NativeResource: |
| 26 |
""" |
| 27 |
Base for classes that bind to a native type. |
| 28 |
_binding is a python capsule referencing the native object. |
| 29 |
|
| 30 |
Note to developers: If NativeResource B depends on the existence of NativeResource A, |
| 31 |
have B's native code Py_INCREF/DECREF A's python class. This ensures that A will not be destroyed before B. |
| 32 |
If we simply had python class B referencing A, and the GC decided to clean up both, it might destroy A before B. |
| 33 |
""" |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
_track_lifetime = False |
| 38 |
_living = WeakSet() |
| 39 |
|
| 40 |
__slots__ = ('_binding', '__weakref__') |
| 41 |
|
| 42 |
def __init__(self): |
| 43 |
if NativeResource._track_lifetime: |
| 44 |
NativeResource._living.add(self) |