Use the existing runloop for sync calls in async handler
envgap__pydantic__httpx2-58
01 / FAILURE SIGNATURE
As reported upstream
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`.
Not a benchmark task.
- The project already builds and runs before the fix, so there is nothing to repair.
02 / ENVIRONMENT RECIPE
- Base commit
37447d0457655265522378346ecf5c72cd346c73- Manifest
pyproject.toml- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
pydantic/httpx2 #58 · read the original issue
> _Originally opened by [`@bennovakovic`](https://github.com/bennovakovic) on 2019-07-31 10:37:10 in [encode/httpx](https://github.com/encode/httpx/issues/179)_
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!04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]