Skip to content

Commit 5b1e870

Browse files
authored
Merge pull request #492 from Carifio24/tornado-to-asyncio
Replace tornado IOLoop with asyncio
2 parents 124e077 + e59f4fc commit 5b1e870

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

glue_jupyter/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import os
22
import functools
33
import collections
4-
import time
54
from io import BytesIO as StringIO
65

76
import IPython
87
import ipyvue
98
import numpy as np
109
import PIL.Image
1110

12-
from tornado.ioloop import IOLoop
11+
from asyncio import get_running_loop
1312

1413
from glue.core import BaseCartesianData
1514
from glue.utils.matplotlib import MATPLOTLIB_GE_36
@@ -106,7 +105,7 @@ def grid_slice(xmin, xmax, shape, ymin, ymax):
106105
def get_ioloop():
107106
ipython = IPython.get_ipython()
108107
if ipython and hasattr(ipython, 'kernel'):
109-
return IOLoop.instance()
108+
return get_running_loop()
110109

111110

112111
def debounced(delay_seconds=0.5, method=False):
@@ -128,11 +127,11 @@ def debounced_execute(counter=counters[key]):
128127
ioloop = get_ioloop()
129128

130129
def thread_safe():
131-
ioloop.add_timeout(time.time() + delay_seconds, debounced_execute)
130+
ioloop.call_later(delay_seconds, debounced_execute)
132131
if ioloop is None: # not IPython, maybe unittest
133132
debounced_execute()
134133
else:
135-
ioloop.add_callback(thread_safe)
134+
ioloop.call_soon_threadsafe(thread_safe)
136135
return execute
137136
return wrapped
138137

0 commit comments

Comments
 (0)