github-actions[bot] commented on code in PR #40507:
URL: https://github.com/apache/beam/pull/40507#discussion_r4360233695
##########
sdks/python/apache_beam/transforms/async_dofn.py:
##########
@@ -209,9 +212,25 @@ def setup(self):
AsyncWrapper._items_in_buffer[self._uuid] = 0
def teardown(self):
- """Forwards to the wrapped dofn's teardown method."""
+ """Waits for this instance's work before tearing down the wrapped dofn."""
+ if self._use_asyncio:
Review Comment:
**🟡 Medium**: If `teardown()` is called when `AsyncWrapper._event_loop` is
`None` (for example, if `self._sync_fn.setup()` raises an exception before the
event loop thread is initialized in `setup()`, or if
`AsyncWrapper.reset_state()` has already been called),
`asyncio.run_coroutine_threadsafe(self._wait_for_async_tasks(),
AsyncWrapper._event_loop)` will raise an `AttributeError` (and emit an
unawaited coroutine warning for `_wait_for_async_tasks()`), preventing
`self._sync_fn.teardown()` from running.
Additionally, initializing `self._pending_futures = set()` and
`self._pending_async_tasks = set()` in `__init__` as well as `setup()` (or
using `getattr`) would avoid an `AttributeError` if `teardown()` or
`schedule_if_room()` is called on an instance where `setup()` was not run.
```suggestion
if self._use_asyncio and AsyncWrapper._event_loop is not None:
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]