Retry reading state.json on failure.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1313
This commit is contained in:
Dan Albert 2021-06-23 20:18:06 -07:00
parent 6f264ff5de
commit ddaef1fb64

View File

@ -382,6 +382,7 @@ class PollDebriefingFileThread(threading.Thread):
else:
last_modified = 0
while not self.stopped():
try:
if (
os.path.isfile("state.json")
and os.path.getmtime("state.json") > last_modified
@ -391,6 +392,11 @@ class PollDebriefingFileThread(threading.Thread):
debriefing = Debriefing(json_data, self.game, self.unit_map)
self.callback(debriefing)
break
except json.JSONDecodeError:
logging.exception(
"Failed to decode state.json. Probably attempted read while DCS "
"was still writing the file. Will retry in 5 seconds."
)
time.sleep(5)