Waits until the event listener reports idle (no new events received in certain timespan). When `t` is provided, ensures waiting for `t` seconds, no matter what. :param t:
(self, t: Union[int, float] = None)
| 298 | asyncio.ensure_future(self.send(cdp_obj)) |
| 299 | |
| 300 | async def wait(self, t: Union[int, float] = None): |
| 301 | """ |
| 302 | Waits until the event listener reports idle |
| 303 | (no new events received in certain timespan). |
| 304 | When `t` is provided, ensures waiting for `t` seconds, no matter what. |
| 305 | :param t: |
| 306 | """ |
| 307 | await self.update_target() |
| 308 | loop = asyncio.get_running_loop() |
| 309 | start_time = loop.time() |
| 310 | with warnings.catch_warnings(): |
| 311 | warnings.filterwarnings( |
| 312 | action="ignore", |
| 313 | category=RuntimeWarning, |
| 314 | message=".*coroutine.*", |
| 315 | ) |
| 316 | try: |
| 317 | if isinstance(t, (int, float)): |
| 318 | try: |
| 319 | # Pass the coroutine directly to wait_for() |
| 320 | await asyncio.wait_for( |
| 321 | self.listener.idle.wait(), timeout=t |
| 322 | ) |
| 323 | except (RuntimeError, asyncio.TimeoutError): |
| 324 | # If the wait_for() fails or errors out, just pass. |
| 325 | # The wait_for() cancels the underlying coroutine. |
| 326 | pass |
| 327 | # Keep waiting until the absolute time 't' has elapsed |
| 328 | while (loop.time() - start_time) < t: |
| 329 | await asyncio.sleep(0.1) |
| 330 | else: |
| 331 | await self.listener.idle.wait() |
| 332 | except asyncio.TimeoutError: |
| 333 | if isinstance(t, (int, float)): |
| 334 | # Explicit time that's given has passed, so leave now. |
| 335 | return |
| 336 | except AttributeError: |
| 337 | # No listener created yet. |
| 338 | pass |
| 339 | |
| 340 | async def set_downloads_folder(self, downloads_path): |
| 341 | if not downloads_path: |
no test coverage detected