question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatible with jupyter

See original GitHub issue
import httpx
httpx.get('https://httpbin.org/get')

When run from Jupyter this snippet produces “Cannot run the event loop while another loop is running” error. Works fine in REPL. Apparently the use of asyncio conflicts with Jupters’s own event loop.

httpx version: 0.7.6 os: Fedora 29 python: Python 3.6.9 ipykernel: 5.1.2 ipython: 7.8.0 jupyter: 5.4.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

3reactions
pquentincommented, Nov 8, 2019

@tomchristie said that he liked that we learned from each other, so I’d like to explain my point above in more detail to explain why it’s actually relevant! It’s not actually the code generation approach that’s important here, but the fact that we’re using the standard library for I/O in the sync case, and not asyncio.

You can keep the async/await annotations and just rely on the fact that all calls will be secretly sync, and wrap the sync API with run_secretly_sync_async_fn (stolen from https://github.com/python-trio/urllib3/issues/1#issuecomment-322028457):

def run_secretly_sync_async_fn(async_fn, *args):
    coro = async_fn(*args)
    try:
        coro.send(None)
    except StopIteration as exc:
        return exc.value
    else:
        raise RuntimeError("you lied, this async function is not secretly synchronous")

The reason we’re not doing this in our urllib3 work is because 1/ we want to support Python 2.7 and 2/ wrapping a large public API with run_secretly_sync_async_fn is actually cumbersome, and adds an unrelated function to the call stack.

But it avoids both code generation and an hidden asyncio loop!

3reactions
pquentincommented, Nov 7, 2019

For what it’s worth, this is one advantage of the code generation approach we use in the urllib3 fork: our sync code is really sync and only uses the standard library for the actual I/O. 99% of the code is shared, only the calls to the specific I/O libraries are different.

Read more comments on GitHub >

github_iconTop Results From Across the Web

incompatibility - All jupyter contrib nbextensions are marked ...
All extensions are marked as "possibly incompatible". A solution is to uncheck the option: "disable configuration for nbextensions without ...
Read more >
All extensions are shown as incompatible · Issue #103 - GitHub
I'm using latest version of Anaconda 3 (python 3.7.1), and followed setup steps for jupyter nbextensions and nbextensions_configurator.
Read more >
Working on Windows - Jupyter Book
Jupyter Book is now also tested against a Windows environment on Python 3.7 ... However, there is a known incompatibility for notebook execution, ......
Read more >
Can't install scala kernel for jupyter notebook (toree)
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the ......
Read more >
Installing IPython — IPython 8.7.0 documentation
Make sure you have the latest version of pip (the Python package manager) installed. If you do not, head to Pip documentation and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found