introduce mutex to avoid multiple token refresh when using threads.

This commit is contained in:
2023-05-09 19:30:07 +09:00
parent 8ee220137f
commit 35defa39a6
3 changed files with 20 additions and 12 deletions

View File

@ -1,3 +1,5 @@
import threading
import requests
from mdrsclient.cache import CacheFile
@ -8,12 +10,14 @@ from mdrsclient.models import Laboratories, Token, User
class MDRSConnection:
url: str
session: requests.Session
lock: threading.Lock
__cache: CacheFile
def __init__(self, remote: str, url: str) -> None:
super().__init__()
self.url = url
self.session = requests.Session()
self.lock = threading.Lock()
self.__cache = CacheFile(remote)
self.__prepare_headers()