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
| Name | Type | Description |
|---|---|---|
| iterable | iterable | The source collection or generator to be consumed. |
| close | callable | A cleanup function to be called when the iterator is exhausted or an exception occurs; typically used to close database connections or file handles. |
Returns
| Type | Description |
|---|---|
generator | A generator that yields items from the original iterable and executes the close callback upon termination or failure. |