Skip to content
This repository has been archived by the owner on Aug 5, 2023. It is now read-only.

Jupyter and Python 3.7 compatibility #17

Closed
gusutabopb opened this issue Sep 4, 2018 · 2 comments
Closed

Jupyter and Python 3.7 compatibility #17

gusutabopb opened this issue Sep 4, 2018 · 2 comments

Comments

@gusutabopb
Copy link
Owner

Currently, the blocking mode won't work on Python 3.7 running on Jupyter. The code below:

import aioinflux
c = aioinflux.InfluxDBClient(db='mydb', mode='blocking')
c.show_measurements()

Raises RuntimeError: This event loop is already running

This is caused by the fact that the latest versions of Tornado (which is used by Jupyter/ipykernel) runs an asyncio loop on the main thread by default:

# Python 3.7
import asyncio
asyncio.get_event_loop()
# <_UnixSelectorEventLoop running=True closed=False debug=False>

# Python 3.6 (w/ tornado < 5)
import asyncio
asyncio.get_event_loop()
# <_UnixSelectorEventLoop running=False closed=False debug=False>

This is being discussed on jupyter/notebook#3397

From an aioinflux perspective, a possible work around would be to start a new event loop on a background thread and use asyncio.run_coroutine_threadsafe to run the coroutine and return a concurrent.futures.Future object that wraps the result.

@gusutabopb
Copy link
Owner Author

Another workaround that does not require any code changes is force-downgrading tornado, as mentioned in this comment: jupyter/notebook#3397 (comment)

@gusutabopb
Copy link
Owner Author

This issue has been fixed as of IPython 7.0. For more details, see this blog post.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant