Skip to content

Commit ac0a730

Browse files
committed
Better handling of some multithreaded tests
1 parent 408e037 commit ac0a730

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import time
1010
import urllib3
1111
import warnings
12+
from importlib.util import find_spec
1213
from selenium import webdriver
1314
from selenium.webdriver.chrome.service import Service as ChromeService
1415
from selenium.webdriver.edge.service import Service as EdgeService
@@ -1232,17 +1233,15 @@ def get_remote_driver(
12321233
device_pixel_ratio,
12331234
):
12341235
if use_wire and selenium4_or_newer:
1235-
driver_fixing_lock = fasteners.InterProcessLock(
1236-
constants.MultiBrowser.DRIVER_FIXING_LOCK
1236+
pip_find_lock = fasteners.InterProcessLock(
1237+
constants.PipInstall.FINDLOCK
12371238
)
1238-
with driver_fixing_lock: # Prevent multi-processes mode issues
1239-
try:
1240-
from seleniumwire import webdriver
1241-
except Exception:
1239+
with pip_find_lock: # Prevent multi-processes mode issues
1240+
if not find_spec("selenium-wire"):
12421241
shared_utils.pip_install(
12431242
"selenium-wire", version=constants.SeleniumWire.VER
12441243
)
1245-
from seleniumwire import webdriver
1244+
from seleniumwire import webdriver
12461245
else:
12471246
from selenium import webdriver
12481247

seleniumbase/fixtures/base_case.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def test_anything(self):
4343
import unittest
4444
import urllib3
4545
from contextlib import contextmanager
46+
from importlib.util import find_spec
4647
from selenium.common.exceptions import (
4748
ElementClickInterceptedException as ECI_Exception,
4849
ElementNotInteractableException as ENI_Exception,
@@ -5901,11 +5902,13 @@ def get_pdf_text(
59015902

59025903
with warnings.catch_warnings():
59035904
warnings.simplefilter("ignore", category=UserWarning)
5904-
try:
5905-
from pdfminer.high_level import extract_text
5906-
except Exception:
5907-
shared_utils.pip_install("pdfminer.six")
5908-
from pdfminer.high_level import extract_text
5905+
pip_find_lock = fasteners.InterProcessLock(
5906+
constants.PipInstall.FINDLOCK
5907+
)
5908+
with pip_find_lock: # Prevent multi-processes mode issues
5909+
if not find_spec("pdfminer.six"):
5910+
shared_utils.pip_install("pdfminer.six")
5911+
from pdfminer.high_level import extract_text
59095912

59105913
if not password:
59115914
password = ""

0 commit comments

Comments
 (0)