diff --git a/playwright/README.md b/playwright/README.md index 66c3409..13aa025 100644 --- a/playwright/README.md +++ b/playwright/README.md @@ -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