Simple example of stream with Asyncio operations
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- python
- Domain
- stream-processing
Research direction
Start by reproducing the Python example from the issue with its aiohttp, asyncio, and Stream(asynchronous=True) pipeline. Read the streamz asyncio-related implementation and existing tests, if present, to determine whether async map operations are supported. Done means the reported pipeline runs correctly or the supported limitation is documented.
Written by the indexing model from the issue text.
Description
Hi,
I've been following the docs and reading through the tests, and I cannot get streamz working with Asyncio :/
Here's a very minimal example of a stream comprising of two async operation and one sync :
- we retrieve content via an aiohttp call
- return content length
- simulate DB write with an Asyncio sleep
- sink to stdout
import asyncio
import aiohttp
from streamz import Stream
async def fetch(url):
print("fetching url {}", url)
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
print(resp.status)
body = await resp.text()
print("Finished w/ url {}", url)
return body
def count(x):
print("I", x)
return len(x)
async def write(x):
await asyncio.sleep(0.2)
print("O", x)
return x
async def f():
print("Starting stream")
source = Stream(asynchronous=True)
source.map(fetch).map(count).map(write).sink(print)
urls = [
'https://httpstatus.io/?i=1',
'https://httpstatus.io/?i=2',
'https://httpstatus.io/?i=3',
'https://httpstatus.io/?i=4',
'https://httpstatus.io/?i=5',
'https://httpstatus.io/?i=6',
]
for u in urls:
await source.emit(u)
if __name__ == '__main__':
asyncio.run(f())
I've tried a lot of combinations using tornado event loop etc. but didn't manage to get anything working.
Is this supposed to be possible or is the Asyncio support still behind?
Am I missing something obvious?
Thanks for the help
- Dominant language
- Python
- Stars
- 1.3k
- Forks
- 149
- Avg merge
- 17h 39m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-streamz/streamz
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
python-streamz/streamz#481 · 4 comments ·
-
Combining the streamz.Stream.filenames() and streamz.Stream.from_textfile() using dask scatter? Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
python-streamz/streamz#480 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-streamz/streamz#479 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-streamz/streamz#478 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 10/100
python-streamz/streamz#476 · 17 comments · 2 reactions ·
All issues in python-streamz/streamz
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
canonical/paas-charm#368 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
tech debt
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
StevenBlack/hosts#3256 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
qualcomm/qai-appbuilder#275 ·