From d32103573d8b0b14a5389651b63f1f3c0df64623 Mon Sep 17 00:00:00 2001 From: Azulinho Date: Sun, 18 Sep 2022 10:20:57 +0100 Subject: [PATCH] FileLock is very slow --- app.py | 4 ++-- lib/helpers.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index f61b268..fd383bc 100644 --- a/app.py +++ b/app.py @@ -24,7 +24,7 @@ import yaml from binance.client import Client from binance.exceptions import BinanceAPIException -from filelock import FileLock +from filelock import SoftFileLock from lz4.frame import open as lz4open from tenacity import retry, wait_exponential @@ -489,7 +489,7 @@ def __init__(self, conn, config_file, config) -> None: self.quit: bool = False # define if we want to use MARKET or LIMIT orders self.order_type: str = config.get("ORDER_TYPE", "MARKET") - self.binance_lock = FileLock("state/binance.lock", timeout=90) + self.binance_lock = SoftFileLock("state/binance.lock", timeout=90) def extract_order_data(self, order_details, coin) -> Dict[str, Any]: """calculate average price and volume for a buy order""" diff --git a/lib/helpers.py b/lib/helpers.py index ce85f76..a370c4e 100644 --- a/lib/helpers.py +++ b/lib/helpers.py @@ -10,7 +10,7 @@ import requests import udatetime from binance.client import Client -from filelock import FileLock +from filelock import SoftFileLock from tenacity import retry, wait_exponential @@ -65,7 +65,7 @@ def requests_with_backoff(query: str): def cached_binance_client(access_key: str, secret_key: str) -> Client: """retry wrapper for binance client first call""" - lock = FileLock("state/binance.client.lockfile", timeout=10) + lock = SoftFileLock("state/binance.client.lockfile", timeout=10) # when running automated-testing with multiple threads, we will hit # api requests limits, this happens during the client initialization # which mostly issues a ping. To avoid this when running multiple processes