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
2730from selenium .webdriver .support .wait import WebDriverWait , TimeoutException , NoSuchElementException
2831from selenium .webdriver .support import expected_conditions as EC
2932from selenium .webdriver .common .print_page_options import PrintOptions
33+ from weakref import ReferenceType , ref
3034
3135from . import config , cv2find , compat
3236from .browsers import BROWSER_CONFIGS , Browser , PageLoadStrategy
4145logger = logging .getLogger (__name__ )
4246
4347
48+ def _cleanup (bot : ReferenceType [WebBot ]):
49+ if bot () is not None :
50+ try :
51+ bot ().stop_browser ()
52+ except Exception :
53+ pass
54+
55+
4456class WebBot (BaseBot ):
4557 KEYS = Keys
4658 DEFAULT_DIMENSIONS = (1600 , 900 )
@@ -80,6 +92,8 @@ def __init__(self, headless=False):
8092
8193 self ._download_folder_path = os .getcwd ()
8294
95+ atexit .register (_cleanup , ref (self ))
96+
8397 def __enter__ (self ):
8498 pass
8599
You can’t perform that action at this time.
0 commit comments