Update playwright/README.md

This commit is contained in:
2024-12-24 07:04:54 +00:00
parent 1b08cc51df
commit eb221c7968

View File

@@ -5,13 +5,12 @@ Linux (WSL Debian)
pip install playwright pip install playwright
playwright install --with-deps playwright install --with-deps
""" """
def sync(func): def sync(f):
import asyncio, threading, queue, functools; asyncio.set_event_loop_policy(None) import asyncio, threading, queue, functools; asyncio.set_event_loop_policy(None)
def server(): sync.q.get(); f, a, kw = sync.obj; sync.obj = f(*a, **kw); sync.q.task_done(); server() def thread(): sync.q.get(); f, a, k = sync.p; sync.p = f(*a, **k); sync.q.task_done(); thread()
if not hasattr(sync, 'q'): sync.q = queue.Queue(); threading.Thread(target=server).start() if not hasattr(sync, 'q'): sync.q = queue.Queue(); threading.Thread(target=thread).start()
@functools.wraps(func) def wrapper(*a, **k): sync.p = f, a, k; sync.q.put(1); sync.q.join(); return sync.p
def wrapper(*a, **kw): sync.obj = func, a, kw; sync.q.put(1); sync.q.join(); return sync.obj return functools.wraps(f)(wrapper)
return wrapper
@sync @sync
def Page(): def Page():
from playwright.sync_api import sync_playwright from playwright.sync_api import sync_playwright