Skip to content

Commit e5833f4

Browse files
committed
Change thread-locking of the proxy zip file to process-locking
1 parent a5fea5c commit e5833f4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
import re
44
import sys
5-
import time
65
import urllib3
76
import warnings
87
from selenium import webdriver
@@ -29,6 +28,7 @@
2928
DISABLE_CSP_ZIP_PATH = "%s/%s" % (EXTENSIONS_DIR, "disable_csp.zip")
3029
PROXY_ZIP_PATH = proxy_helper.PROXY_ZIP_PATH
3130
PROXY_ZIP_PATH_2 = proxy_helper.PROXY_ZIP_PATH_2
31+
PROXY_ZIP_LOCK = proxy_helper.PROXY_ZIP_LOCK
3232
PLATFORM = sys.platform
3333
IS_WINDOWS = False
3434
LOCAL_CHROMEDRIVER = None
@@ -93,21 +93,18 @@ def _add_chrome_proxy_extension(
9393
""" Implementation of https://stackoverflow.com/a/35293284 for
9494
https://stackoverflow.com/questions/12848327/
9595
(Run Selenium on a proxy server that requires authentication.) """
96-
import random
9796
arg_join = " ".join(sys.argv)
98-
if not ("-n" in sys.argv or "-n=" in arg_join or arg_join == "-c"):
97+
if not ("-n" in sys.argv or " -n=" in arg_join or arg_join == "-c"):
9998
# Single-threaded
10099
proxy_helper.create_proxy_zip(proxy_string, proxy_user, proxy_pass)
101100
else:
102101
# Pytest multi-threaded test
103-
import threading
104-
lock = threading.Lock()
105-
with lock:
106-
time.sleep(random.uniform(0.02, 0.15))
102+
import fasteners
103+
proxy_zip_lock = fasteners.InterProcessLock(PROXY_ZIP_LOCK)
104+
with proxy_zip_lock:
107105
if not os.path.exists(PROXY_ZIP_PATH):
108106
proxy_helper.create_proxy_zip(
109107
proxy_string, proxy_user, proxy_pass)
110-
time.sleep(random.uniform(0.1, 0.2))
111108
proxy_zip = PROXY_ZIP_PATH
112109
if not os.path.exists(PROXY_ZIP_PATH):
113110
# Handle "Permission denied" on the default proxy.zip path

seleniumbase/core/proxy_helper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
PROXY_ZIP_PATH = "%s/%s" % (DRIVER_DIR, "proxy.zip")
88
DOWNLOADS_DIR = constants.Files.DOWNLOADS_FOLDER
99
PROXY_ZIP_PATH_2 = "%s/%s" % (DOWNLOADS_DIR, "proxy.zip")
10+
PROXY_ZIP_LOCK = "%s/%s" % (DOWNLOADS_DIR, "proxy.lock")
1011

1112

1213
def create_proxy_zip(proxy_string, proxy_user, proxy_pass):
@@ -90,5 +91,7 @@ def remove_proxy_zip_if_present():
9091
os.remove(PROXY_ZIP_PATH)
9192
elif os.path.exists(PROXY_ZIP_PATH_2):
9293
os.remove(PROXY_ZIP_PATH_2)
94+
if os.path.exists(PROXY_ZIP_LOCK):
95+
os.remove(PROXY_ZIP_LOCK)
9396
except Exception:
9497
pass

0 commit comments

Comments
 (0)