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
playwright install --with-deps
"""
def sync(func):
def sync(f):
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()
if not hasattr(sync, 'q'): sync.q = queue.Queue(); threading.Thread(target=server).start()
@functools.wraps(func)
def wrapper(*a, **kw): sync.obj = func, a, kw; sync.q.put(1); sync.q.join(); return sync.obj
return wrapper
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=thread).start()
def wrapper(*a, **k): sync.p = f, a, k; sync.q.put(1); sync.q.join(); return sync.p
return functools.wraps(f)(wrapper)
@sync
def Page():
from playwright.sync_api import sync_playwright