Originally opened by @bennovakovic on 2019-07-31 10:37:10 in encode/httpx
Hi, this library looks awesome and I really want to use it; but I seem to have hit a blocker and can't seem to find a solution in the docs.
TL;DR: Is there any way to provide our own runloop when using the sync calls as looking through the source the sync calls are actually using the async request call.
Basically I'm writing a client api that provides 2 interfaces; an async and sync interface.
The issue that i am having is that if I try to use the sync methods with an existing runloop (provided by Sanic in this scenario), it complains with the exception: Cannot run the event loop while another loop is running.
Essentially I'm just calling:
import httpx
...
class SomeClass(object):
def get_some_url(self):
r = httpx.get('some url')
note that nothing here is async; apart from the fact that the .get_some_url call is made from within an async function like so:
import SomeClass
async def handler(request):
o = SomeClass()
o.get_some_url()
This works fine when using the async calls like this:
import httpx
...
class SomeClass(object):
async def get_some_url(self):
client = httpx.AsyncClient()
r = await client.get('some url')
import SomeClass
async def handler(request):
o = SomeClass()
await o.get_some_url()
So I was just wondering if its possible to provide our own runloop when using the sync calls? Sanic uses uvloop internally, would be nice to be able to just pass that straight in somehow when constructing the httpx object, or setting it as a property after import.
Thanks!
Hi, this library looks awesome and I really want to use it; but I seem to have hit a blocker and can't seem to find a solution in the docs.
TL;DR: Is there any way to provide our own runloop when using the
synccalls as looking through the source the sync calls are actually using the async request call.Basically I'm writing a client api that provides 2 interfaces; an async and sync interface.
The issue that i am having is that if I try to use the sync methods with an existing runloop (provided by Sanic in this scenario), it complains with the exception:
Cannot run the event loop while another loop is running.Essentially I'm just calling:
note that nothing here is async; apart from the fact that the
.get_some_urlcall is made from within an async function like so:This works fine when using the async calls like this:
So I was just wondering if its possible to provide our own runloop when using the sync calls? Sanic uses uvloop internally, would be nice to be able to just pass that straight in somehow when constructing the
httpxobject, or setting it as a property after import.Thanks!