File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ import atexit
14import base64
25import functools
36import glob
2528from selenium .webdriver .remote .webelement import WebElement
2629from selenium .webdriver .support .wait import WebDriverWait , TimeoutException , NoSuchElementException
2730from selenium .webdriver .support import expected_conditions as EC
31+ from weakref import ReferenceType , ref
2832
2933from . import config , cv2find
3034from .browsers import BROWSER_CONFIGS , Browser , PageLoadStrategy
3943logger = logging .getLogger (__name__ )
4044
4145
46+ def _cleanup (bot : ReferenceType [WebBot ]):
47+ if bot () is not None :
48+ try :
49+ bot ().stop_browser ()
50+ except Exception :
51+ pass
52+
53+
4254class WebBot (BaseBot ):
4355 KEYS = Keys
4456 DEFAULT_DIMENSIONS = (1600 , 900 )
@@ -77,6 +89,8 @@ def __init__(self, headless=False):
7789
7890 self ._download_folder_path = os .getcwd ()
7991
92+ atexit .register (_cleanup , ref (self ))
93+
8094 def __enter__ (self ):
8195 pass
8296
You can’t perform that action at this time.
0 commit comments