From 5a3d7aa5c9644c10d6588531208517a06db6d77d Mon Sep 17 00:00:00 2001 From: Bla Date: Fri, 27 Oct 2023 16:43:12 +0000 Subject: [PATCH] concurrently running instances of chromium are fucking each other up --- server-web.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/server-web.py b/server-web.py index 9f0afd3..2b4240f 100644 --- a/server-web.py +++ b/server-web.py @@ -91,7 +91,7 @@ def ids(): l = filter(idIsRecent,list(valuestore.keys())) return ','.join(map(str,list(l))) -def createDriver(): +def createDriver(id): options = webdriver.ChromeOptions() options.add_argument('--headless') options.add_argument("--incognito") @@ -101,7 +101,15 @@ def createDriver(): options.add_argument("--no-sandbox") options.add_argument("--enable-javascript") options.add_argument('--disable-dev-shm-usage') - driver = webdriver.Chrome(options=options) + data_dir = "--user-data-dir=/tmp/" + str(id) + options.add_argument(data_dir) + + try: + driver = webdriver.Chrome(options=options) + except selenium.common.exceptions.SessionNotCreatedException: + sleep(10) + driver = createDriver(id) + return driver driver.response_interceptor = interceptor return driver @@ -115,7 +123,7 @@ if __name__ == '__main__': restartWait = timedelta(hours=4) # setup webdriver - d0 = createDriver() + d0 = createDriver(0) # start initial driver d0.get('https://dus-travis.dus.com/') @@ -125,14 +133,14 @@ if __name__ == '__main__': while True: sleep(30) if datetime.now(timezone.utc) > lastaccess + restartWait: - d1 = createDriver() + d1 = createDriver(1) d1.get('https://dus-travis.dus.com/') print ("New Failover Driver started, waiting 10 seconds ...") sleep(10) killChildren(d0) del d0 print ("Original driver deleted") - d0 = createDriver() + d0 = createDriver(0) d0.get('https://dus-travis.dus.com/') print ("Recreating original driver and waiting 10 seconds ...") sleep(10)