Skip to content

Commit

Permalink
fix: use threading lock instead of boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoOwO authored Jul 3, 2021
1 parent 3f34011 commit 06c3406
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,15 @@
# }

global save_lock
save_lock = False
save_lock = threading.Lock()
def save():
global save_lock
while save_lock:
time.sleep(0.1)

save_lock = True
save_lock.acquire()

with open(const.FETCHED_JSON, "w", encoding="utf8") as f:
json.dump(fetched, f, indent=4, ensure_ascii=False)

save_lock = False
save_lock.release()

if os.path.isfile(const.FETCHED_JSON):
with open(const.FETCHED_JSON, encoding="utf8") as f:
Expand Down Expand Up @@ -274,4 +271,4 @@ def clear_chat():
if const.CHAT_DIR:
chat_expiry_task.stop()
for video_id in chats:
chats[video_id].stop()
chats[video_id].stop()

0 comments on commit 06c3406

Please sign in to comment.