Skip to content

Commit

Permalink
Don't await saving files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariko Wakabayashi committed Dec 1, 2020
1 parent b6b4b28 commit c35b04a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 23 deletions.
21 changes: 0 additions & 21 deletions jupyter_server/services/contents/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,24 +416,3 @@ async def _read_file(self, os_path, format):
reason='bad format',
) from e
return encodebytes(bcontent).decode('ascii'), 'base64'

async def _save_file(self, os_path, content, format):
"""Save content of a generic file."""
if format not in {'text', 'base64'}:
raise HTTPError(
400,
"Must specify format of file contents as 'text' or 'base64'",
)
try:
if format == 'text':
bcontent = content.encode('utf8')
else:
b64_bytes = content.encode('ascii')
bcontent = decodebytes(b64_bytes)
except Exception as e:
raise HTTPError(
400, u'Encoding error saving %s: %s' % (os_path, e)
) from e

with self.atomic_writing(os_path, text=False) as f:
await run_sync_in_worker_thread(f.write, bcontent)
2 changes: 1 addition & 1 deletion jupyter_server/services/contents/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ async def save(self, model, path=''):
await self.create_checkpoint(path)
elif model['type'] == 'file':
# Missing format will be handled internally by _save_file.
await self._save_file(os_path, model['content'], model.get('format'))
self._save_file(os_path, model['content'], model.get('format'))
elif model['type'] == 'directory':
await self._save_directory(os_path, model, path)
else:
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/contents/largefilemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def save(self, model, path=''):
if chunk == 1:
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)
await super(AsyncLargeFileManager, self)._save_file(os_path, model['content'], model.get('format'))
super(AsyncLargeFileManager, self)._save_file(os_path, model['content'], model.get('format'))
else:
await self._save_large_file(os_path, model['content'], model.get('format'))
except web.HTTPError:
Expand Down

0 comments on commit c35b04a

Please sign in to comment.