Base classes¶
Base classes for native resource handlers and reference counting. You may inherit from these if you need your own custom wrapper around your native resources.
Base classes for reference counting
NativeHandle
¶
Bases: ReferenceCounter
A base class for wrappers around otherwise "unmanaged" resources e.g. in a native library.
Attributes:
Name | Type | Description |
---|---|---|
_handle |
object
|
The handle (e.g. cffi pointer) to the native resource. |
_finalizing |
bool
|
a flag telling whether this object is in its deletion phase. This has a use in some advanced cases with reverse callback, possibly not relevant in Python. |
Source code in refcount/base.py
__init__(handle=None, prior_ref_count=0)
¶
initialize a reference counter for a resource handle, with an initial reference count.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle |
object
|
The handle (e.g. cffi pointer) to the native resource. |
None
|
prior_ref_count |
int
|
the initial reference count. Default 0 if this NativeHandle is sole responsible for the lifecycle of the resource. |
0
|
Source code in refcount/base.py
ReferenceCounter
¶
Bases: object
A base class for reference counters
Attributes:
Name | Type | Description |
---|---|---|
reference_count |
int
|
property getter, reference count |
Source code in refcount/base.py
reference_count: int
property
¶
Get the current reference count
__init__(prior_ref_count=0)
¶
Initialize this with an initial reference count.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prior_ref_count |
int
|
the initial reference count. Default 0 if this object is sole responsible for the lifecycle of the resource. |
0
|
Source code in refcount/base.py
add_ref()
¶
Manually increment the reference count.
Users usually have no need to call this method. They may have to if they manage cases where one native handle wrapper uses another wrapper (and its underlying resource).
Source code in refcount/base.py
decrement_ref()
¶
Manually increment the reference count.
Users usually have no need to call this method. They may have to if they manage cases where one native handle wrapper uses another wrapper (and its underlying resource).