Skip to content

Commit 2ab7981

Browse files
committed
usb1: Document the (internal) _LibUSB1Finalizer class
1 parent 11e700b commit 2ab7981

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

usb1/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ def create_binary_buffer(init_or_size):
174174
return create_initialised_buffer(init_or_size)
175175

176176
class _LibUSB1Finalizer: # pylint: disable=too-few-public-methods
177+
"""
178+
Create, and keep track of, finalizer objects.
179+
Allows outstanding finalizers to be triggered, typically so C resources
180+
owned by the objects associated with those finalizers are freed before
181+
another one they depend (and owned by the instance of this class) on may
182+
be freed.
183+
"""
177184
def __init__(self):
178185
self._finalizer_dict = {}
179186
self.__finalizer_id_generator = itertools.count()
@@ -187,6 +194,14 @@ def __finalize(handle, pop, func, kw):
187194
pop(handle)
188195

189196
def _getFinalizer(self, obj, func, **kw):
197+
"""
198+
Creates and adds to _finalizer_dict a finalizer which will trigger
199+
after obj becomes unreachable and before it is garbage-collected.
200+
When it triggers, func(**kw) is called and the finalizer is removed
201+
from _finalizer_dict.
202+
203+
Returns the created finalizer object.
204+
"""
190205
with self.__finalizer_id_generator_lock:
191206
handle = next(self.__finalizer_id_generator)
192207
finalizer_dict = self._finalizer_dict

0 commit comments

Comments
 (0)