# # from __future__ import absolute_import from asynchttp import Http from httplib2 import ServerNotFoundError from pprint import pprint import logging fmt = '%(asctime)s %(thread)d %(name)s %(levelname)-8s %(message)s' #logging.basicConfig(level=logging.DEBUG, format=fmt) http = Http() response, content = http.request('http://proximobus.appspot.com/agencies.json') # do something else here while the request is being downloaded and decoded... # if you want to do the decoding of json and some processing in the background # see callback.py pprint(content) response, content = http.request( 'http://some.bad.address.that.does.not.exist/') # do something else where the request is processing, the exception will happen # in the worker. # when you go to access the result the exception will be raised try:
from __future__ import absolute_import from asynchttp import Http from pprint import pprint from json import loads import logging fmt = '%(asctime)s %(thread)d %(name)s %(levelname)-8s %(message)s' #logging.basicConfig(level=logging.DEBUG, format=fmt) http = Http() def callback(promise): promise.response.data = loads(promise.content) response, content = http.request('http://proximobus.appspot.com/agencies.json', callback=callback) # do something else here while the request is being downloaded and decoded... pprint(response.data) # handling exceptions in callbacks class SomeException(Exception): pass def failing_callback(promise): raise SomeException('catch me if you can') response, content = http.request('http://proximobus.appspot.com/agencies.json', callback=failing_callback)
# # from __future__ import absolute_import from asynchttp import Http from httplib2 import ServerNotFoundError from pprint import pprint import logging fmt = '%(asctime)s %(thread)d %(name)s %(levelname)-8s %(message)s' #logging.basicConfig(level=logging.DEBUG, format=fmt) http = Http() response, content = http.request('http://proximobus.appspot.com/agencies.json') # do something else here while the request is being downloaded and decoded... # if you want to do the decoding of json and some processing in the background # see callback.py pprint(content) response, content = http.request('http://some.bad.address.that.does.not.exist/') # do something else where the request is processing, the exception will happen # in the worker. # when you go to access the result the exception will be raised try: