From 815ed3ce561bbbe39e34fe09c1d0bda2a7077766 Mon Sep 17 00:00:00 2001 From: Michal Charemza Date: Sat, 13 Oct 2018 22:46:31 +0100 Subject: [PATCH] Allow more contents manager functions to return futures This allows slower contents managers to not block the event loop by allowing more of their API to return futures. Other usages of contents manager functions are already wrapped in maybe_future, including a use of `file_exists` in contents/handlers.py --- notebook/files/handlers.py | 4 ++-- notebook/services/contents/handlers.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/notebook/files/handlers.py b/notebook/files/handlers.py index 7973fd691..1da0ad71d 100644 --- a/notebook/files/handlers.py +++ b/notebook/files/handlers.py @@ -12,7 +12,7 @@ except ImportError: #PY2 from base64 import decodestring as decodebytes -from tornado import web +from tornado import gen, web from notebook.base.handlers import IPythonHandler @@ -51,7 +51,7 @@ class FilesHandler(IPythonHandler): else: name = path - model = cm.get(path, type='file', content=include_body) + model = yield gen.maybe_future(cm.get(path, type='file', content=include_body)) if self.get_argument("download", False): self.set_attachment_header(name) diff --git a/notebook/services/contents/handlers.py b/notebook/services/contents/handlers.py index 25dcaf213..8756ae60c 100644 --- a/notebook/services/contents/handlers.py +++ b/notebook/services/contents/handlers.py @@ -182,10 +182,12 @@ class ContentsHandler(APIHandler): cm = self.contents_manager - if cm.file_exists(path): + file_exists = yield gen.maybe_future(cm.file_exists(path)) + if file_exists: raise web.HTTPError(400, "Cannot POST to files, use PUT instead.") - if not cm.dir_exists(path): + dir_exists = yield gen.maybe_future(cm.dir_exists(path)) + if not dir_exists: raise web.HTTPError(404, "No such directory: %s" % path) model = self.get_json_body()