02.10.06 — The Playwright actor: one owner thread#
Source folder:
src/ocarina/infra/playwright/The Playwright adapter mirrors the Selenium one file for file (
create_driver,create_drivers_pool,create_screenshotter,driver_healthcheck,mixins), with one extra file:driver.py. That file deserves a chapter of its own. It is what reconciles Playwright’s sync API — inherently bound to one thread — with Ocarina’s threaded model (pool, warmup, Watcher). The model has been stressed and stabilized; it holds.
The problem: Playwright’s sync API is thread-affine#
Playwright’s sync API binds every object it hands out — Playwright, Browser, BrowserContext, Page, Locator, … — to the thread that called sync_playwright().start(). Under the hood it is a greenlet pinned to that thread. Touching any of them from another thread raises: