Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Trip coroutine demo
import time, functools
import requests, trip
def timeit(fn):
start_time = time.time()
fn()
return time.time() - start_time
url = 'http://httpbin.org/get'
times = 10 # 100 changed for inland network delay
def fetch():
r = [requests.get(url) for i in range(times)]
return r
@trip.coroutine
def async_fetch():
r = yield [trip.get(url) for i in range(times)]
raise trip.Return(r)
print('Non-trip cost: %ss' % timeit(fetch))
print('Trip cost: %ss' % timeit(functools.partial(trip.run, async_fetch)))
# Non-trip cost: 17.90799999237s
# Trip cost: 0.172300004959s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.