Re: https://discord.com/channels/267624335836053506/1231477734069374996
I am trying to convert this synchronous code to asynchronous and i am half way through thanks to @twin peak but i am unsure how to proceed with the tricky part.
import contextlib
from urllib.request import urlopen
from aiofiles import os, open
async def info(inp):
async with openstream(inp) as stream:
return await probe(stream)
@contextlib.asynccontextmanager
async def openstream(inp):
if hasattr(inp, 'read'):
yield inp
elif inp.startswith('http'):
# `tricky part`
with contextlib.closing(urlopen(inp)) as f:
yield f
# `tricky part`
else:
pass
i am looking to discuss this as i a a novice in asyncio.