Skip to content

Commit

Permalink
Fix issue with exception wrapping in gen transform
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshardmind committed Jan 20, 2025
1 parent a00fa7b commit 352a43a
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/async_utils/gen_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,25 @@ def _consumer[**P, Y](
*args: P.args,
**kwargs: P.kwargs,
) -> None:
gen = f(*args, **kwargs)
try:
gen = f(*args, **kwargs)

for val in gen:
laziness_ev.wait()
queue.sync_put(val)
laziness_ev.clear()
for val in gen:
laziness_ev.wait()
queue.sync_put(val)
laziness_ev.clear()

if cancel_future.cancelled():
gen.throw(cf.CancelledError)

if cancel_future.done():
if exc := cancel_future.exception():
gen.throw(type(exc), exc)
else:
if cancel_future.cancelled():
gen.throw(cf.CancelledError)

if cancel_future.done():
if exc := cancel_future.exception():
gen.throw(type(exc), exc)
else:
gen.throw(cf.CancelledError)
except StopIteration:
pass


class ACTX[Y]:
"""Context manager to forward exception context to generator in thread.
Expand Down

0 comments on commit 352a43a

Please sign in to comment.