Comments (2)
Hi @t-mart, thanks for your report :)
I tried to reproduce your problem, and I did get a proper exception out of it. For instance, consider the following code:
import asyncio
from aiostream import operator
@operator(pipable=True)
async def some_pipable_operator(source, arg):
await asyncio.sleep(1)
async def main():
some_pipable_operator("test")
if __name__ == "__main__":
asyncio.run(main())
Just like in your snippet, regenerate
is incorrectly instantiated:
- the first argument is not an async iterable
- the second argument is missing
In this case it's the first error that is reported first:
Traceback (most recent call last):
File "test.py", line 15, in <module>
asyncio.run(main())
File "/home/vinmic/miniconda/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/home/vinmic/miniconda/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "test.py", line 12, in main
some_pipable_operator("test")
File "/home/vinmic/aiostream/aiostream/core.py", line 284, in init
assert_async_iterable(args[0])
File "/home/vinmic/aiostream/aiostream/aiter_utils.py", line 61, in assert_async_iterable
f"{type(obj).__name__!r} object is not async iterable")
TypeError: 'str' object is not async iterable
For your information, the proper usage of user-defined pipable operator is:
import asyncio
from aiostream import stream, operator
@operator(pipable=True)
async def some_pipable_operator(source, arg):
assert await source == "a"
yield arg
async def main():
result = await (stream.just("a") | some_pipable_operator.pipe("b"))
assert result == "b"
if __name__ == "__main__":
asyncio.run(main())
However, it seems to me that you don't need a user-defined pipable operator. Instead, you may simply use stream.map:
from functools import partial
from aiostream import stream, pipe
async def watch(app: web.Application) -> None:
await (
stream.merge(*[awatch(p) for p in watch_paths])
| pipe.map(partial(regenerate, app=app), task_limit=1)
)
async def regenerate(
changedset: Set[Tuple[Change, str]], app: web.Application
) -> None:
[...]
Hope that helps :)
from aiostream.
Fantastic. Thank you for your help.
I wasn't getting the exception because, while I did create_task
all this code, I wasn't awaiting it, and that maybe caused the exception to not bubble up properly. (It's amazing it was running at all. Maybe aiohttp application.on_startup
was helping me in some way I don't understand.) EDIT: Or it was because I didn't debug=True
the loop...no matter. It's not important. For many Python programmers, thinking asynchronously will take some getting-used-to.
Sorry to stuff up your issues with a non-issue. I'd definitely be in favor of a help channel of some kind, whether that be gitter or IRC or discord etc.
from aiostream.
Related Issues (20)
- Incompatibility with mypy 1.7 and later
- Docstring and prototype not properly shown with pylance HOT 1
- New operators
- No easy to see installation instructions in the docs or README HOT 1
- merge causes anext(): asynchronous generator is already running Exception HOT 2
- question: how to use chain HOT 8
- Feature suggestion: `strict` parameter for `zip` HOT 3
- How to duplicate streams properly? HOT 5
- add support python3.10 HOT 1
- Please upload a wheel release to pypi HOT 2
- `stream.list` implementation is x10 slower than using plain Python built-in functionality (list comprehension) HOT 2
- Idea: Timeouts on chunks HOT 4
- action: support task_limit HOT 5
- Regarding `update_pipe_module` HOT 3
- Aiostream fails to import with a TypeError HOT 1
- CI test pipeline doesn't run in Python 3.12: ModuleNotFoundError: No module named 'setuptools' HOT 6
- License change HOT 3
- 0.5.0 (#84) made backwards incompatible changes HOT 6
- asyncio.Event for graceful/early termination HOT 7
- How to handle stream splitting HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiostream.