Skip to content

Commit

Permalink
hotfix for race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
jobrachem committed Dec 8, 2023
1 parent 05cbe98 commit 0e3c7e9
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/alfred3_interact/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,31 @@ def query(self) -> dict:
return q

def load(self):
if self.saving_method == "mongo":
data = self._load_mongo()
elif self.saving_method == "local":
data = self._load_local()
data = data["members"][self.sid]
self.member.data = GroupMemberData(**data)
start = time.time()
end = start + 15
current = start
while current <= end:
try:
if self.saving_method == "mongo":
data = self._load_mongo()
elif self.saving_method == "local":
data = self._load_local()

data = data["members"][self.sid]
self.member.data = GroupMemberData(**data)

return

except KeyError:
time.sleep(1)
current = time.time()
msg = "Error while loading."
if current <= end:
msg += " Trying again."
else:
msg += " Timeout reached. Aborting."

self.exp.log.exception(msg)

def _load_local(self) -> dict:
with open(self.path, encoding="utf-8") as f:
Expand Down

0 comments on commit 0e3c7e9

Please sign in to comment.