02.10.06 — L’acteur Playwright : un thread propriétaire#
Dossier source :
src/ocarina/infra/playwright/L’adapter Playwright reprend la structure de l’adapter Selenium fichier pour fichier (
create_driver,create_drivers_pool,create_screenshotter,driver_healthcheck,mixins), avec un fichier en plus :driver.py. Ce fichier mérite un chapitre à lui seul. C’est lui qui réconcilie l’API sync de Playwright, intrinsèquement liée à un thread, avec le modèle threadé d’Ocarina (pool, warmup, Watcher).
Le problème : l’API sync de Playwright est thread-affine#
L’API sync de Playwright lie chaque objet qu’elle renvoie (Playwright, Browser, BrowserContext, Page, Locator, …) au thread qui a appelé sync_playwright().start(). Sous le capot, c’est un greenlet épinglé à ce thread. Y toucher depuis un autre thread lève :