Skip to main content

closing_iterator_wrapper

Wraps an iterable to ensure a cleanup callback is executed upon completion while temporarily disconnecting and reconnecting the request_finished signal handler.

def closing_iterator_wrapper(
iterable: iterable,
close: callable
) - > generator

Wraps an iterable to ensure a cleanup callback is executed after iteration completes, while temporarily suspending and restoring the default database connection management signals.

Parameters

NameTypeDescription
iterableiterableThe source collection or generator to be consumed.
closecallableA cleanup function to be called when the iterator is exhausted or an exception occurs; typically used to close database connections or file handles.

Returns

TypeDescription
generatorA generator that yields items from the original iterable and executes the close callback upon termination or failure.