Skip to content

Commit

Permalink
Allow more contents manager functions to return futures
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michalc committed Oct 17, 2018
1 parent b663bf1 commit 815ed3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions notebook/files/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from base64 import decodestring as decodebytes


from tornado import web
from tornado import gen, web

from notebook.base.handlers import IPythonHandler

Expand Down Expand Up @@ -51,7 +51,7 @@ def get(self, path, include_body=True):
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)
Expand Down
6 changes: 4 additions & 2 deletions notebook/services/contents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ def post(self, path=''):

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()
Expand Down

0 comments on commit 815ed3c

Please sign in to comment.