mirror of https://gitlab.com/bashrc2/epicyon
More exception information
parent
4783a336f1
commit
4f3ecf57c4
13
utils.py
13
utils.py
|
@ -874,14 +874,14 @@ def remove_avatar_from_cache(base_dir: str, actor_str: str) -> None:
|
||||||
def save_json(json_object: {}, filename: str) -> bool:
|
def save_json(json_object: {}, filename: str) -> bool:
|
||||||
"""Saves json to a file
|
"""Saves json to a file
|
||||||
"""
|
"""
|
||||||
tries = 0
|
tries = 1
|
||||||
while tries < 5:
|
while tries <= 5:
|
||||||
try:
|
try:
|
||||||
with open(filename, 'w+', encoding='utf-8') as json_file:
|
with open(filename, 'w+', encoding='utf-8') as json_file:
|
||||||
json_file.write(json.dumps(json_object))
|
json_file.write(json.dumps(json_object))
|
||||||
return True
|
return True
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: save_json ' + str(tries))
|
print('EX: save_json ' + str(tries) + ' ' + str(filename))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
tries += 1
|
tries += 1
|
||||||
return False
|
return False
|
||||||
|
@ -893,15 +893,16 @@ def load_json(filename: str, delay_sec: int = 2, max_tries: int = 5) -> {}:
|
||||||
if '/Actor@' in filename:
|
if '/Actor@' in filename:
|
||||||
filename = filename.replace('/Actor@', '/inbox@')
|
filename = filename.replace('/Actor@', '/inbox@')
|
||||||
json_object = None
|
json_object = None
|
||||||
tries = 0
|
tries = 1
|
||||||
while tries < max_tries:
|
while tries <= max_tries:
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r', encoding='utf-8') as json_file:
|
with open(filename, 'r', encoding='utf-8') as json_file:
|
||||||
data = json_file.read()
|
data = json_file.read()
|
||||||
json_object = json.loads(data)
|
json_object = json.loads(data)
|
||||||
break
|
break
|
||||||
except BaseException:
|
except BaseException:
|
||||||
print('EX: load_json exception ' + str(filename))
|
print('EX: load_json exception ' +
|
||||||
|
str(tries) + ' ' + str(filename))
|
||||||
if delay_sec > 0:
|
if delay_sec > 0:
|
||||||
time.sleep(delay_sec)
|
time.sleep(delay_sec)
|
||||||
tries += 1
|
tries += 1
|
||||||
|
|
Loading…
Reference in New Issue