playwright chromium could not be successfully closed
def run(playwright, url: str, doc: dict, proxy):
browser = None
try:
browser = playwright.chromium.launch(proxy=proxy)
context = browser.new_context()
context.set_default_navigation_timeout(600000)
# 拦截请求 def block_images_and_css(route, request): if request.resourcetype in ["image", "stylesheet", "script"]: route.abort() else: route.continue()
context.route("*/", block_images_and_css) page = context.new_page() page.goto(url) page.evaluate("window.scrollTo(0, document.body.scrollHeight)") page.wait_for_load_state("domcontentloaded") except Exception as e: print(f"An error occurred: {e}") finally: if browser: browser.close()
# 拦截请求 def block_images_and_css(route, request): if request.resourcetype in ["image", "stylesheet", "script"]: route.abort() else: route.continue()
context.route("*/", block_images_and_css) page = context.new_page() page.goto(url) page.evaluate("window.scrollTo(0, document.body.scrollHeight)") page.wait_for_load_state("domcontentloaded") except Exception as e: print(f"An error occurred: {e}") finally: if browser: browser.close()
5 Replies
can you confirm that you have a lot of chromium zombie processes?
check it with:
if yes, you can set up a cronjob that runs daily and deletes all defunct processes. the only way to do that is to kill the parent process. which is
windmill
crontab could look like this:
since windmill runs in a docker container that automatically restarts on failure there is little to no downtime for the workers.
this is the only way i found to solve this problem - at least for my caseOk, thanks for your reply
also, you should probably also close the context before the browser:
https://playwright.dev/docs/api/class-browsercontext#browser-context-close
BrowserContext | Playwright
BrowserContexts provide a way to operate multiple independent browser sessions.
hey @Alper would
0 0 * * * /usr/bin/killall -9 windmil
run on windmill itself - e.g. should I make it a bash script on windmill that automatically runs?
No, in my case it needs to be executed on the host machine that runs the windmill worker