|
2 | 2 | import os
|
3 | 3 | import re
|
4 | 4 | import sys
|
5 |
| -import time |
6 | 5 | import urllib3
|
7 | 6 | import warnings
|
8 | 7 | from selenium import webdriver
|
|
29 | 28 | DISABLE_CSP_ZIP_PATH = "%s/%s" % (EXTENSIONS_DIR, "disable_csp.zip")
|
30 | 29 | PROXY_ZIP_PATH = proxy_helper.PROXY_ZIP_PATH
|
31 | 30 | PROXY_ZIP_PATH_2 = proxy_helper.PROXY_ZIP_PATH_2
|
| 31 | +PROXY_ZIP_LOCK = proxy_helper.PROXY_ZIP_LOCK |
32 | 32 | PLATFORM = sys.platform
|
33 | 33 | IS_WINDOWS = False
|
34 | 34 | LOCAL_CHROMEDRIVER = None
|
@@ -93,21 +93,18 @@ def _add_chrome_proxy_extension(
|
93 | 93 | """ Implementation of https://stackoverflow.com/a/35293284 for
|
94 | 94 | https://stackoverflow.com/questions/12848327/
|
95 | 95 | (Run Selenium on a proxy server that requires authentication.) """
|
96 |
| - import random |
97 | 96 | 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"): |
99 | 98 | # Single-threaded
|
100 | 99 | proxy_helper.create_proxy_zip(proxy_string, proxy_user, proxy_pass)
|
101 | 100 | else:
|
102 | 101 | # 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: |
107 | 105 | if not os.path.exists(PROXY_ZIP_PATH):
|
108 | 106 | proxy_helper.create_proxy_zip(
|
109 | 107 | proxy_string, proxy_user, proxy_pass)
|
110 |
| - time.sleep(random.uniform(0.1, 0.2)) |
111 | 108 | proxy_zip = PROXY_ZIP_PATH
|
112 | 109 | if not os.path.exists(PROXY_ZIP_PATH):
|
113 | 110 | # Handle "Permission denied" on the default proxy.zip path
|
|
0 commit comments