Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Webagg backend: get rid of tornado#20591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
599708a Webagg backend: get rid of tornado
martinRenoubd06c97 Update lib/matplotlib/backends/backend_webagg_core.py
martinRenouabd9efe Remove other references to TimerTornado (unused?)
martinRenoub420b3e create_task -> ensure_future so that it works also if there is no event
martinRenou8fd2c59 Put back TimerTornado class
martinRenouaad08b2 DOC: add minimum version of tornado to ensure asyncio integration
tacaswellFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletiondoc/devel/dependencies.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletionlib/matplotlib/backends/backend_nbagg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionlib/matplotlib/backends/backend_webagg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -36,7 +36,7 @@ | ||
| from matplotlib.backend_bases import _Backend | ||
| from matplotlib._pylab_helpers import Gcf | ||
| from . import backend_webagg_core as core | ||
martinRenou marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| from .backend_webagg_core importTimerAsyncio,TimerTornado | ||
| class ServerThread(threading.Thread): | ||
45 changes: 42 additions & 3 deletionslib/matplotlib/backends/backend_webagg_core.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,8 +8,9 @@ | ||
| # way over a web socket. | ||
| # | ||
| # - `backend_webagg.py` contains a concrete implementation of a basic | ||
| # application, implemented withasyncio. | ||
| import asyncio | ||
| import datetime | ||
| from io import BytesIO, StringIO | ||
| import json | ||
| @@ -19,7 +20,6 @@ | ||
| import numpy as np | ||
| from PIL import Image | ||
| from matplotlib import _api, backend_bases, backend_tools | ||
| from matplotlib.backends import backend_agg | ||
| @@ -85,6 +85,8 @@ def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| def _timer_start(self): | ||
| import tornado | ||
| self._timer_stop() | ||
| if self._single: | ||
| ioloop = tornado.ioloop.IOLoop.instance() | ||
| @@ -98,6 +100,8 @@ def _timer_start(self): | ||
| self._timer.start() | ||
| def _timer_stop(self): | ||
| import tornado | ||
| if self._timer is None: | ||
| return | ||
| elif self._single: | ||
| @@ -114,8 +118,43 @@ def _timer_set_interval(self): | ||
| self._timer_start() | ||
| class TimerAsyncio(backend_bases.TimerBase): | ||
| def __init__(self, *args, **kwargs): | ||
| self._task = None | ||
| super().__init__(*args, **kwargs) | ||
| async def _timer_task(self, interval): | ||
| while True: | ||
| try: | ||
| await asyncio.sleep(interval) | ||
| self._on_timer() | ||
| if self._single: | ||
| break | ||
| except asyncio.CancelledError: | ||
| break | ||
| def _timer_start(self): | ||
| self._timer_stop() | ||
| self._task = asyncio.ensure_future( | ||
martinRenou marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| self._timer_task(max(self.interval / 1_000., 1e-6)) | ||
| ) | ||
QuLogic marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| def _timer_stop(self): | ||
| if self._task is not None: | ||
| self._task.cancel() | ||
| self._task = None | ||
| def _timer_set_interval(self): | ||
| # Only stop and restart it if the timer has already been started | ||
| if self._task is not None: | ||
| self._timer_stop() | ||
| self._timer_start() | ||
| class FigureCanvasWebAggCore(backend_agg.FigureCanvasAgg): | ||
| _timer_cls =TimerAsyncio | ||
| # Webagg and friends having the right methods, but still | ||
| # having bugs in practice. Do not advertise that it works until | ||
| # we can debug this. | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.