MCPcopy Index your code
hub / github.com/microsoft/playwright-python / _sync_gather_impl

Function _sync_gather_impl

tests/sync/conftest.py:98–127  ·  view source on GitHub ↗
(*actions: Callable)

Source from the content-addressed store, hash-verified

96@pytest.fixture(scope="session")
97def sync_gather(playwright: Playwright) -> Generator[Callable, None, None]:
98 def _sync_gather_impl(*actions: Callable) -> List[Any]:
99 g_self = greenlet.getcurrent()
100 results: Dict[Callable, Any] = {}
101 exceptions: List[Exception] = []
102
103 def action_wrapper(action: Callable) -> Callable:
104 def body() -> Any:
105 try:
106 results[action] = action()
107 except Exception as e:
108 results[action] = e
109 exceptions.append(e)
110 g_self.switch()
111
112 return body
113
114 async def task() -> None:
115 for action in actions:
116 g = greenlet(action_wrapper(action))
117 g.switch()
118
119 asyncio.create_task(task())
120
121 while len(results) < len(actions):
122 playwright._dispatcher_fiber.switch()
123
124 if exceptions:
125 raise exceptions[0]
126
127 return list(map(lambda action: results[action], actions))
128
129 yield _sync_gather_impl
130

Callers

nothing calls this directly

Calls 1

taskFunction · 0.85

Tested by

no test coverage detected