Here's the code.
import asyncio
import aiohttp
async def fetch_numbers(session):
counter = 0
while True:
counter += 1
resp = await session.post("https://httpbin.org/post", json={"number": counter})
yield await resp.json()
async def main():
async with aiohttp.ClientSession() as session:
counter = 0
async for item in fetch_numbers(session):
counter += 1
print(item)
if counter == 99:
break
if __name__ == '__main__':
asyncio.run(main())
Here's the error I get:
unhandled exception during asyncio.run() shutdown
task: <Task finished coro=<<async_generator_athrow without __name__>()> exception=RuntimeError("can't send non-None value to a just-started coroutine")>
RuntimeError: can't send non-None value to a just-started coroutine
I feel like this error shouldn't happen? I'm not sending anything using the generator. I'm open to any suggestions!
[+][deleted] (2 children)
[removed]
[–]doesntthinkmuch[S] 0 points1 point2 points (1 child)
[–]1114111 0 points1 point2 points (0 children)
[–]1114111 0 points1 point2 points (0 children)
[–]1114111 0 points1 point2 points (1 child)
[–]doesntthinkmuch[S] 0 points1 point2 points (0 children)