From 2f72166787dde23b6d5beb1db090996592d3a6f8 Mon Sep 17 00:00:00 2001 From: sh4mh1 <148555284+shamhi@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:51:38 +0300 Subject: [PATCH 1/2] Add condition for chrome options --- bot/utils/scripts.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/utils/scripts.py b/bot/utils/scripts.py index 2842cae..632426e 100644 --- a/bot/utils/scripts.py +++ b/bot/utils/scripts.py @@ -133,8 +133,10 @@ def escape_html(text: str) -> str: options.add_argument("--headless") options.add_argument("--log-level=3") -options.add_argument('--no-sandbox') -options.add_argument('--disable-dev-shm-usage') +if os.name == 'posix': + options.add_argument('--no-sandbox') + options.add_argument('--disable-dev-shm-usage') + driver = None session_queue = Queue() From a548805630215e8e20302b4f5cf4e1263c467221 Mon Sep 17 00:00:00 2001 From: Ahrorbek Abdullayev Date: Fri, 12 Jul 2024 02:51:07 +0500 Subject: [PATCH 2/2] Update scripts.py (implement alternative way to calculate qsize) on macOS qsize doesn't work so added a function to calculate it manually --- bot/utils/scripts.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bot/utils/scripts.py b/bot/utils/scripts.py index 632426e..e7f636b 100644 --- a/bot/utils/scripts.py +++ b/bot/utils/scripts.py @@ -198,6 +198,19 @@ def extract_chq(chq: str) -> int: return chr_key, cache_id +def safe_qsize(queue: Queue) -> int: + try: + return queue.qsize() + except NotImplementedError: + # Alternative way to count items if qsize() is not implemented + count = 0 + while not queue.empty(): + queue.get() + count += 1 + # Re-populate the queue + for _ in range(count): + queue.put(1) + return count # Other way def login_in_browser(auth_url: str, proxy: str) -> tuple[str, str, str]: @@ -253,11 +266,11 @@ def login_in_browser(auth_url: str, proxy: str) -> tuple[str, str, str]: session_queue.put(1) - if len(get_session_names()) == session_queue.qsize(): + if len(get_session_names()) == safe_qsize(session_queue): logger.info("All sessions are closed. Quitting driver...") driver.quit() driver = None - while session_queue.qsize() > 0: + while safe_qsize(session_queue) > 0: session_queue.get() return response_text, x_cv, x_touch