# Path: benchmarks/utils.py
# def log_time(name):
#     def wrapper(func):
#         def run(*args, **kwargs):
#             start = time.time()
#             res = func(*args, **kwargs)
#             print('The execution time of {}: {}'.format(name, time.time() - start))
#             return res
# 
#         return run
# 
#     return wrapper


from threading import Thread, Semaphore
from collections import deque
from selenium.webdriver import Chrome, ChromeOptions
from benchmarks.utils import log_time
            pass


def reset_driver(driver):
    assert isinstance(driver, Chrome)
    driver.execute_script('window.open();')
    handles = driver.window_handles
    for i in range(0, len(handles) - 1):
        driver.switch_to.window(handles[i])
        driver.close()
    driver.switch_to.window(handles[-1])


def manage_chrome_tabs_thread(sem, manager):
    driver = None
    try:
        driver = manager.get_driver()
        driver.get(TEST_URL)
        reset_driver(driver)
    except Exception as e:
        print(e)
        if driver is not None:
            driver.quit()
            driver = None
    finally:
        if driver is not None:
            manager.push_driver(driver)
        sem.release()



# Path: benchmarks/utils.py
# def log_time(name):
#     def wrapper(func):
#         def run(*args, **kwargs):
#             start = time.time()
#             res = func(*args, **kwargs)
#             print('The execution time of {}: {}'.format(name, time.time() - start))
#             return res
# 
#         return run
# 
#     return wrapper


# Path: benchmarks/chrome_driver_manage_benchmark.py
from threading import Thread, Semaphore
from collections import deque
from selenium.webdriver import Chrome, ChromeOptions
from benchmarks.utils import log_time

            pass


def reset_driver(driver):
    assert isinstance(driver, Chrome)
    driver.execute_script('window.open();')
    handles = driver.window_handles
    for i in range(0, len(handles) - 1):
        driver.switch_to.window(handles[i])
        driver.close()
    driver.switch_to.window(handles[-1])


def manage_chrome_tabs_thread(sem, manager):
    driver = None
    try:
        driver = manager.get_driver()
        driver.get(TEST_URL)
        reset_driver(driver)
    except Exception as e:
        print(e)
        if driver is not None:
            driver.quit()
            driver = None
    finally:
        if driver is not None:
            manager.push_driver(driver)
        sem.release()



@log_time('manage chrome tabs')