theelous3 / asks

Async requests-like httplib for python.
MIT License
508 stars 63 forks source link

Updated trio example in README issue #87 #88

Closed VinceBackpack closed 6 years ago

VinceBackpack commented 6 years ago

Updated trio example in readme for issue #87

theelous3 commented 6 years ago

That code when given real urls does not run. You need to pass the session (s) and path correctly:


import asks
import trio
asks.init(trio)

path_list = ['http://httpbin.org/get']

results = []

async def worker(s, path):
    r = await s.get(path)
    results.append(r)

async def main(path_list):
    from asks.sessions import Session
    s = Session('https://example.org' , connections=2)
    async with trio.open_nursery() as n:
        for path in path_list:
            n.start_soon(worker, s, path)

s = asks.Session()
trio.run(main, path_list)
theelous3 commented 6 years ago

Last thing I promise. Replace the url with the fake urls, but everything else is good.

We don't want someone to grab this code, do for path in path_list * 1000: and annoy httpbin.org with 1k pointless requests :D

VinceBackpack commented 6 years ago

Will do! Thanks for the helpful feedbacks btw.

theelous3 commented 6 years ago

good stuff ty