Skip to content

Conversation

@florimondmanca
Copy link
Contributor

@florimondmanca florimondmanca commented Nov 7, 2019

Fixes #508

This is an attempt at handling the situation in which users try to use httpx.get() or httpx.Client() in an async environment that has a running loop (e.g. in a Jupyter notebook).

I documented several potential caveats in the form of code comments.

I still need to verify this actually solves the Jupyter use case, though the tests give me hope that it does. :-)

@florimondmanca
Copy link
Contributor Author

florimondmanca commented Nov 8, 2019

@encode/httpx-maintainers OK, I think I've got something that passes the tests. Basically we're checking if the event loop is running and when relevant run the coroutine in a worker thread instead. This thing is inspired by asgiref's AsyncToSync utility. Definitely needs some cleanup, but at least it seems to work. Also todo: handle shutdown of the threadpool executor (via a new backend.close() method, probably).

@florimondmanca florimondmanca force-pushed the feat/asyncio-client-sync-in-async branch from bf7f207 to b651380 Compare November 8, 2019 21:14
@florimondmanca
Copy link
Contributor Author

Closing as I don't think this will make it, probably in favor of a SyncBackend (unless #522 is accepted) - see #508 (comment).

@florimondmanca florimondmanca deleted the feat/asyncio-client-sync-in-async branch November 12, 2019 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incompatible with jupyter

2 participants