Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,37 @@ You can use alternative event loops by passing the correct sleep function:
async def my_async_trio_function_with_sleep():
...

Generators
~~~~~~~~~~

``retry`` does not support generator or async generator functions. Decorating a
generator with ``@retry`` will not retry on exceptions raised during iteration
— the decorator wraps the function call itself, which for generators simply
returns a generator object without executing any of the body.

Also note that generators passed *as arguments* to a retried function will be
exhausted after the first attempt and will not be rewound automatically on
retry. If you need to pass a generator as an argument, consider passing a
factory function instead:

.. code-block:: python

# Bad: generator will be exhausted after the first attempt
@retry
def process(items):
for item in items:
do_work(item)

process(my_generator()) # retries will see an empty generator

# Good: pass a factory so a fresh generator is created on each attempt
@retry
def process(items_factory):
for item in items_factory():
do_work(item)

process(my_generator) # each retry gets a fresh generator

Contribute
----------

Expand Down
Loading