joetong
joetong3mo ago

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()
5 Replies
Alper
Alper3mo ago
can you confirm that you have a lot of chromium zombie processes? check it with:
# ps aux | grep defunct
root 3397781 0.0 0.0 0 0 ? Z Sep05 0:00 [chrome] <defunct>
root 3397782 0.0 0.0 0 0 ? Z Sep05 0:00 [chrome] <defunct>
root 3397893 0.0 0.0 0 0 ? Z Sep05 0:00 [chrome] <defunct>
...
# ps aux | grep defunct
root 3397781 0.0 0.0 0 0 ? Z Sep05 0:00 [chrome] <defunct>
root 3397782 0.0 0.0 0 0 ? Z Sep05 0:00 [chrome] <defunct>
root 3397893 0.0 0.0 0 0 ? Z Sep05 0:00 [chrome] <defunct>
...
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:
0 0 * * * /usr/bin/killall -9 windmil
0 0 * * * /usr/bin/killall -9 windmil
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 case
joetong
joetongOP3mo ago
Ok, thanks for your reply
Alper
Alper3mo ago
also, you should probably also close the context before the browser:
context.close()
context.close()
https://playwright.dev/docs/api/class-browsercontext#browser-context-close
BrowserContext | Playwright
BrowserContexts provide a way to operate multiple independent browser sessions.
giyu
giyu2w ago
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?
Alper
Alper2w ago
No, in my case it needs to be executed on the host machine that runs the windmill worker