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

Commitcced93b

Browse files
authored
Merge pull request#20591 from martinRenou/asyncio_timer
MNT: defer tornado import as long as possible
2 parents7d741df +aad08b2 commitcced93b

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

‎doc/devel/dependencies.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ and the capabilities they provide.
4646
*wxPython_ (>= 4) [#]_: for the wx-based backends.
4747
*pycairo_ (>= 1.11.0) orcairocffi_ (>= 0.8): for the GTK and/or cairo-based
4848
backends.
49-
*Tornado_: for the WebAgg backend.
49+
*Tornado_ (>=5): for the WebAgg backend.
5050

5151
.. _Tk:https://docs.python.org/3/library/tk.html
5252
.. _PyQt5:https://pypi.org/project/PyQt5/

‎lib/matplotlib/backends/backend_nbagg.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
frommatplotlib.backend_basesimport_Backend,NavigationToolbar2
2323
frommatplotlib.backends.backend_webagg_coreimport (
2424
FigureCanvasWebAggCore,FigureManagerWebAgg,NavigationToolbar2WebAgg,
25-
TimerTornado)
25+
TimerTornado,TimerAsyncio
26+
)
2627

2728

2829
defconnection_info():

‎lib/matplotlib/backends/backend_webagg.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
frommatplotlib.backend_basesimport_Backend
3737
frommatplotlib._pylab_helpersimportGcf
3838
from .importbackend_webagg_coreascore
39-
from .backend_webagg_coreimportTimerTornado
39+
from .backend_webagg_coreimportTimerAsyncio,TimerTornado
4040

4141

4242
classServerThread(threading.Thread):

‎lib/matplotlib/backends/backend_webagg_core.py‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
# way over a web socket.
99
#
1010
# - `backend_webagg.py` contains a concrete implementation of a basic
11-
# application, implemented withtornado.
11+
# application, implemented withasyncio.
1212

13+
importasyncio
1314
importdatetime
1415
fromioimportBytesIO,StringIO
1516
importjson
@@ -19,7 +20,6 @@
1920

2021
importnumpyasnp
2122
fromPILimportImage
22-
importtornado
2323

2424
frommatplotlibimport_api,backend_bases,backend_tools
2525
frommatplotlib.backendsimportbackend_agg
@@ -85,6 +85,8 @@ def __init__(self, *args, **kwargs):
8585
super().__init__(*args,**kwargs)
8686

8787
def_timer_start(self):
88+
importtornado
89+
8890
self._timer_stop()
8991
ifself._single:
9092
ioloop=tornado.ioloop.IOLoop.instance()
@@ -98,6 +100,8 @@ def _timer_start(self):
98100
self._timer.start()
99101

100102
def_timer_stop(self):
103+
importtornado
104+
101105
ifself._timerisNone:
102106
return
103107
elifself._single:
@@ -114,8 +118,43 @@ def _timer_set_interval(self):
114118
self._timer_start()
115119

116120

121+
classTimerAsyncio(backend_bases.TimerBase):
122+
def__init__(self,*args,**kwargs):
123+
self._task=None
124+
super().__init__(*args,**kwargs)
125+
126+
asyncdef_timer_task(self,interval):
127+
whileTrue:
128+
try:
129+
awaitasyncio.sleep(interval)
130+
self._on_timer()
131+
132+
ifself._single:
133+
break
134+
exceptasyncio.CancelledError:
135+
break
136+
137+
def_timer_start(self):
138+
self._timer_stop()
139+
140+
self._task=asyncio.ensure_future(
141+
self._timer_task(max(self.interval/1_000.,1e-6))
142+
)
143+
144+
def_timer_stop(self):
145+
ifself._taskisnotNone:
146+
self._task.cancel()
147+
self._task=None
148+
149+
def_timer_set_interval(self):
150+
# Only stop and restart it if the timer has already been started
151+
ifself._taskisnotNone:
152+
self._timer_stop()
153+
self._timer_start()
154+
155+
117156
classFigureCanvasWebAggCore(backend_agg.FigureCanvasAgg):
118-
_timer_cls=TimerTornado
157+
_timer_cls=TimerAsyncio
119158
# Webagg and friends having the right methods, but still
120159
# having bugs in practice. Do not advertise that it works until
121160
# we can debug this.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp