-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ AsyncIterDataPipe for running concurrent tasks
An asynchronous iterable-style DataPipe for processing tasks concurrently! Composition over inheritance. Subclassing from collections.abc.AsyncIterable in Python's standard library. Added some basic API docstring, and have setup some extlinks and intersphinx mappings in the docs/_config.yml file for linking to terms in the Python glossary.
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
An asynchronous-style DataPipe is one that implements the | ||
:py:meth:`__aiter__ <object.__aiter__>` protocol, and represents an | ||
:py-term:`asynchronous iterable <asynchronous-iterable>` over data samples. | ||
This is well-suited for cases when I/O latency is slow, e.g. when waiting on | ||
network connections, or performing read operations on multiple files at once. | ||
""" | ||
|
||
from bambooflow.datapipes.aiter import AsyncIterDataPipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Base classes for Asynchronous Iterable DataPipes. | ||
""" | ||
import collections | ||
|
||
|
||
class AsyncIterDataPipe(collections.abc.AsyncIterable): | ||
""" | ||
Asynchronous iterable-style DataPipes. | ||
All DataPipes that represent an asynchronous iterable of data samples | ||
should subclass this. This style of DataPipes is particularly useful for | ||
performing I/O-bound tasks such as streaming data from a network disk drive | ||
or reading multiple files concurrently. ``AsyncIterDataPipe`` is | ||
initialized in a lazy fashion, and its elements are computed only when | ||
:py:meth:`__anext__ <object.__anext__>` is called on the async iterator of | ||
an ``AsyncIterDataPipe``. | ||
""" | ||
|
||
def __repr__(self) -> str: | ||
# Instead of showing <bamboopipe. ... .AsyncIterableWrapper at 0x.....>, | ||
# return the class name like <AsyncIterableWrapper> | ||
return str(self.__class__.__qualname__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
# API Reference | ||
|
||
## Asynchronous-style DataPipes | ||
|
||
```{eval-rst} | ||
.. automodule:: bambooflow | ||
.. automodule:: bambooflow.datapipes | ||
:members: | ||
.. autoclass:: bambooflow.datapipes.AsyncIterDataPipe | ||
:show-inheritance: | ||
``` |