Skip to content

Commit 53792c6

Browse files
authored
Merge pull request #229 from vicsanity623/pyob-evolution-v2-1773706935
Lock Implementation for File Concurrency Control in Dashboard Server
2 parents a493673 + 71d7ee5 commit 53792c6

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/pyob/dashboard_server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import signal
55
import sys
6+
import threading
67
from datetime import datetime
78

89
from flask import Flask, jsonify, render_template
@@ -12,6 +13,7 @@
1213
app = Flask(__name__)
1314

1415
logger = logging.getLogger(__name__)
16+
status_lock = threading.Lock() # Initialize a lock for issue_statuses.json
1517
data_parser_instance = DataParser() # Initialize DataParser once globally
1618

1719

@@ -61,9 +63,10 @@ def acknowledge_issue(issue_id):
6163
try:
6264
status_file = "issue_statuses.json"
6365
issue_statuses = {}
64-
if os.path.exists(status_file):
65-
with open(status_file, "r", encoding="utf-8") as f:
66-
issue_statuses = json.load(f)
66+
with status_lock: # Acquire lock before reading/writing shared resource
67+
if os.path.exists(status_file):
68+
with open(status_file, "r", encoding="utf-8") as f:
69+
issue_statuses = json.load(f)
6770

6871
# Update status for the given issue_id
6972
issue_statuses[issue_id] = {

0 commit comments

Comments
 (0)