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 path plus .lock.

  • encoding – Text encoding used for writing.

  • timeout – Maximum seconds to wait for the lock.

  • **json_kwargs – Keyword arguments passed to json.dumps.

Note

Example

>>> safe_write_json_with_lock("data.json", {"ok": True})
Returns:

The destination path.

Return type:

Path