Skip to content

Commit b7a354d

Browse files
committed
Allow contents manager get to return future
This is a follow up to jupyter#4099, wrapping other uses of contents manager get with `maybe_future` to allow it to yield the event loop.
1 parent 9640e1f commit b7a354d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

notebook/nbconvert/handlers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import os
88
import zipfile
99

10-
from tornado import web, escape
10+
from tornado import gen, web, escape
1111
from tornado.log import app_log
1212

1313
from ..base.handlers import (
1414
IPythonHandler, FilesRedirectHandler,
1515
path_regex,
1616
)
17+
from ..utils import maybe_future
1718
from nbformat import from_dict
1819

1920
from ipython_genutils.py3compat import cast_bytes
@@ -86,6 +87,7 @@ def content_security_policy(self):
8687
"; sandbox allow-scripts"
8788

8889
@web.authenticated
90+
@gen.coroutine
8991
def get(self, format, path):
9092

9193
exporter = get_exporter(format, config=self.config, log=self.log)
@@ -99,7 +101,7 @@ def get(self, format, path):
99101
else:
100102
ext_resources_dir = None
101103

102-
model = self.contents_manager.get(path=path)
104+
model = yield maybe_future(self.contents_manager.get(path=path))
103105
name = model['name']
104106
if model['type'] != 'notebook':
105107
# not a notebook, redirect to files

notebook/notebook/handlers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55

66
from collections import namedtuple
77
import os
8-
from tornado import web
8+
from tornado import (
9+
gen, web,
10+
)
911
HTTPError = web.HTTPError
1012

1113
from ..base.handlers import (
1214
IPythonHandler, FilesRedirectHandler, path_regex,
1315
)
14-
from ..utils import url_escape
16+
from ..utils import (
17+
maybe_future, url_escape,
18+
)
1519
from ..transutils import _
1620

1721

@@ -68,6 +72,7 @@ def get_frontend_exporters():
6872
class NotebookHandler(IPythonHandler):
6973

7074
@web.authenticated
75+
@gen.coroutine
7176
def get(self, path):
7277
"""get renders the notebook template if a name is given, or
7378
redirects to the '/files/' handler if the name is not given."""
@@ -76,7 +81,7 @@ def get(self, path):
7681

7782
# will raise 404 on not found
7883
try:
79-
model = cm.get(path, content=False)
84+
model = yield maybe_future(cm.get(path, content=False))
8085
except web.HTTPError as e:
8186
if e.status_code == 404 and 'files' in path.split('/'):
8287
# 404, but '/files/' in URL, let FilesRedirect take care of it

0 commit comments

Comments
 (0)