Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
tacaswell merged 6 commits intomatplotlib:mainfrommartinRenou:asyncio_timer
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletiondoc/devel/dependencies.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ and the capabilities they provide.
* wxPython_ (>= 4) [#]_: for the wx-based backends.
* pycairo_ (>= 1.11.0) or cairocffi_ (>= 0.8): for the GTK and/or cairo-based
backends.
* Tornado_: for the WebAgg backend.
* Tornado_ (>=5): for the WebAgg backend.

.. _Tk: https://docs.python.org/3/library/tk.html
.. _PyQt5: https://pypi.org/project/PyQt5/
Expand Down
3 changes: 2 additions & 1 deletionlib/matplotlib/backends/backend_nbagg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,8 @@
from matplotlib.backend_bases import _Backend, NavigationToolbar2
from matplotlib.backends.backend_webagg_core import (
FigureCanvasWebAggCore, FigureManagerWebAgg, NavigationToolbar2WebAgg,
TimerTornado)
TimerTornado, TimerAsyncio
)


def connection_info():
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/backends/backend_webagg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,7 @@
from matplotlib.backend_bases import _Backend
from matplotlib._pylab_helpers import Gcf
from . import backend_webagg_core as core
from .backend_webagg_core import TimerTornado
from .backend_webagg_core importTimerAsyncio,TimerTornado


class ServerThread(threading.Thread):
Expand Down
45 changes: 42 additions & 3 deletionslib/matplotlib/backends/backend_webagg_core.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,9 @@
# way over a web socket.
#
# - `backend_webagg.py` contains a concrete implementation of a basic
# application, implemented withtornado.
# application, implemented withasyncio.

import asyncio
import datetime
from io import BytesIO, StringIO
import json
Expand All@@ -19,7 +20,6 @@

import numpy as np
from PIL import Image
import tornado

from matplotlib import _api, backend_bases, backend_tools
from matplotlib.backends import backend_agg
Expand DownExpand Up@@ -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()
Expand All@@ -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:
Expand All@@ -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(
self._timer_task(max(self.interval / 1_000., 1e-6))
)

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 =TimerTornado
_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.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp