[JsonIO] race condition fix (#2308)

* race condition fix

* style fix
This commit is contained in:
Michael H 2018-11-23 18:11:59 -05:00 committed by Toby Harradine
parent 9d22d5b7b5
commit ca533f8937

View File

@ -3,6 +3,7 @@ import json
import os
import asyncio
import logging
from copy import deepcopy
from uuid import uuid4
# This is basically our old DataIO and just a base for much more elaborate classes
@ -69,7 +70,11 @@ class JsonIO:
async def _threadsafe_save_json(self, data, settings=PRETTY):
loop = asyncio.get_event_loop()
func = functools.partial(self._save_json, data, settings)
# the deepcopy is needed here. otherwise,
# the dict can change during serialization
# and this will break the encoder.
data_copy = deepcopy(data)
func = functools.partial(self._save_json, data_copy, settings)
async with self._lock:
await loop.run_in_executor(None, func)