Skip to content

Commit

Permalink
Merge pull request #59 from inception-project/bugfix/58-Recommender-o…
Browse files Browse the repository at this point in the history
…nly-ever-trained-once

#58 - Recommender only ever trained once
  • Loading branch information
reckart authored Mar 12, 2024
2 parents 409739b + 5fad012 commit 538ef21
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ariadne/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ def _train(self, classifier_name: str):
# The lock needs to be acquired out here, not in the fn scope, else it would
# just throw the Timeout inside fn.
lock = self._get_lock(classifier.name, user_id)
logger.debug(f'Acquiring lock for [{user_id}, {classifier.name}]')
lock.acquire()

def _fn():
try:
classifier.fit(req.documents, req.layer, req.feature, req.project_id, user_id)
finally:
logger.debug(f'Releasing lock for [{user_id}, {classifier.name}]')
lock.release()

# We spawn a thread and run the training in there so that this HTTP request can return directly
Expand All @@ -92,4 +94,4 @@ def _fn():
def _get_lock(self, classifier_name: str, user_id: str) -> FileLock:
self._lock_directory.mkdir(parents=True, exist_ok=True)
lock_path = self._lock_directory / f"{classifier_name}_{user_id}.lock"
return FileLock(lock_path, timeout=1)
return FileLock(lock_path, timeout=1, thread_local=False)

0 comments on commit 538ef21

Please sign in to comment.