-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
System info
- Playwright Version: [v1.27.0]
- Operating System: [All]
- Browser: [All, Chromium, Firefox, WebKit]
- Other info:
Source code
import signal
import time
from playwright.sync_api import sync_playwright
def my_sig_handler(signum, frame):
global exit
exit = True
exit = False
playwright = sync_playwright().start()
browser = playwright.chromium.launch(headless=False)
context = browser.new_context(record_har_path="/Users/chenstrace/example.har")
page = context.new_page()
page.goto("https://www.baidu.com/")
signal.signal(signal.SIGINT, my_sig_handler)
try:
while True:
if exit:
break
else:
print("sleep 1", flush=True)
time.sleep(1)
finally:
print("close context", flush=True)
context.close()
print("close browser", flush=True)
browser.close()
Steps
- save the code to file a.py
- run the program in terminal, using
python3 a.py
- wait for 5 seconds
- press CTRL+C in terminal.
Expected
- python program can exit
- a har file was saved to /Users/chenstrace/example.har
Actual
- the program hangs on context.close()
- no har file was saved.