File: __init__.py

package info (click to toggle)
aws-crt-python 0.16.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 78,328 kB
  • sloc: ansic: 330,743; python: 18,949; makefile: 6,271; sh: 3,712; asm: 754; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (38 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

from weakref import WeakSet

__all__ = [
    'auth',
    'crypto',
    'http',
    'io',
    'mqtt',
    's3',
    'websocket',
]

__version__ = '1.0.0.dev0'


class NativeResource:
    """
    Base for classes that bind to a native type.
    _binding is a python capsule referencing the native object.

    Note to developers: If NativeResource B depends on the existence of NativeResource A,
    have B's native code Py_INCREF/DECREF A's python class. This ensures that A will not be destroyed before B.
    If we simply had python class B referencing A, and the GC decided to clean up both, it might destroy A before B.
    """

    # For tracking live NativeResources in tests/debug.
    # Note that WeakSet can accurately report if 0 objects exist, but iteration isn't 100% thread-safe.
    _track_lifetime = False
    _living = WeakSet()

    __slots__ = ('_binding', '__weakref__')

    def __init__(self):
        if NativeResource._track_lifetime:
            NativeResource._living.add(self)