mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-18 11:55:46 +08:00
Write notebook.json file atomically
This commit is contained in:
parent
08a17dfcf0
commit
dd5778b81d
@ -91,12 +91,16 @@ class BaseJSONConfigManager(LoggingConfigurable):
|
|||||||
filename = self.file_name(section_name)
|
filename = self.file_name(section_name)
|
||||||
self.ensure_config_dir_exists()
|
self.ensure_config_dir_exists()
|
||||||
|
|
||||||
|
# Generate the JSON up front, since it could raise an exception,
|
||||||
|
# in order to avoid writing half-finished corrupted data to disk.
|
||||||
|
json_content = json.dumps(data, indent=2)
|
||||||
|
|
||||||
if PY3:
|
if PY3:
|
||||||
f = io.open(filename, 'w', encoding='utf-8')
|
f = io.open(filename, 'w', encoding='utf-8')
|
||||||
else:
|
else:
|
||||||
f = open(filename, 'wb')
|
f = open(filename, 'wb')
|
||||||
with f:
|
with f:
|
||||||
json.dump(data, f, indent=2)
|
f.write(json_content)
|
||||||
|
|
||||||
def update(self, section_name, new_data):
|
def update(self, section_name, new_data):
|
||||||
"""Modify the config section by recursively updating it with new_data.
|
"""Modify the config section by recursively updating it with new_data.
|
||||||
|
Loading…
Reference in New Issue
Block a user