pyufunc.safe_write_json_with_lock#
- pyufunc.safe_write_json_with_lock(path, data, *, lock_path=None, encoding='utf-8', timeout=-1, **json_kwargs)#
Write JSON while holding a file lock.
- Parameters:
path – Destination file path.
data – JSON-serializable data.
lock_path – Optional lock-file path. Defaults to
pathplus.lock.encoding – Text encoding used for writing.
timeout – Maximum seconds to wait for the lock.
**json_kwargs – Keyword arguments passed to
json.dumps.
Note
Source package:
filelock.Source repository: tox-dev/py-filelock
Source document: https://py-filelock.readthedocs.io
Source license: MIT License.
Example
>>> safe_write_json_with_lock("data.json", {"ok": True})
- Returns:
The destination path.
- Return type:
Path