Skip to content

Commit

Permalink
Merge pull request #99 from kayqueGovetri/FIX/implement-atexit-browser
Browse files Browse the repository at this point in the history
FIX: Implement atexit to stop browser
  • Loading branch information
hhslepicka committed Nov 21, 2023
2 parents b592e15 + d1aa707 commit 7ab885f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions botcity/web/bot.py
@@ -1,3 +1,6 @@
from __future__ import annotations

import atexit
import base64
import functools
import glob
Expand Down Expand Up @@ -27,6 +30,7 @@
from selenium.webdriver.support.wait import WebDriverWait, TimeoutException, NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.print_page_options import PrintOptions
from weakref import ReferenceType, ref

from . import config, cv2find, compat
from .browsers import BROWSER_CONFIGS, Browser, PageLoadStrategy
Expand All @@ -41,6 +45,14 @@
logger = logging.getLogger(__name__)


def _cleanup(bot: ReferenceType[WebBot]):
if bot() is not None:
try:
bot().stop_browser()
except Exception:
pass


class WebBot(BaseBot):
KEYS = Keys
DEFAULT_DIMENSIONS = (1600, 900)
Expand Down Expand Up @@ -80,6 +92,8 @@ def __init__(self, headless=False):

self._download_folder_path = os.getcwd()

atexit.register(_cleanup, ref(self))

def __enter__(self):
pass

Expand Down

0 comments on commit 7ab885f

Please sign in to comment.