From 55ea983bda17baa74bd736ff52cc3653b4aa743a Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 1 Dec 2022 19:32:05 +0100 Subject: [PATCH] BrowserSteps - Forcefully shutdown playwright to prevent any race-conditions waiting for it to shutdown --- .../blueprint/browser_steps/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/changedetectionio/blueprint/browser_steps/__init__.py b/changedetectionio/blueprint/browser_steps/__init__.py index 44dfd701..e4112521 100644 --- a/changedetectionio/blueprint/browser_steps/__init__.py +++ b/changedetectionio/blueprint/browser_steps/__init__.py @@ -49,16 +49,20 @@ def cleanup_playwright_session(): import psutil + # playwright's .stop() seems to hang, so lets kill the processes before calling .stop + # a bit hard, but more reliable :/ current_process = psutil.Process() children = current_process.children(recursive=True) for child in children: - print (child) - print('Child pid is {}'.format(child.pid)) - - # .stop() hangs sometimes if its called when there are no children to process - # but how do we know this is our child? dunno - if children: - browsersteps_playwright_browser_interface.stop() + # @todo a bug here is that we could be accidently shutting down the playwright from the content checker + if "playwright" in child.name() or child.name() == "node": + print(child) + print('Child pid is {}, killing'.format(child.pid)) + child.terminate() + + print ("Shutting down playwright interface .stop()") + browsersteps_playwright_browser_interface.stop() + print ("Shutdown of playwright complete") browsersteps_live_ui_o = {} browsersteps_playwright_browser_interface = None