MCPcopy
hub / github.com/reflex-dev/reflex / poll_for_stopped_progress

Function poll_for_stopped_progress

tests/integration/test_upload.py:500–535  ·  view source on GitHub ↗

Poll for progress dictionaries to stop updating. Args: get_progress_dicts: A callable that returns the list of progress dictionary elements. iterations: Maximum number of iterations to poll for. delay: Delay in seconds between iterations. stable_iterations: Numbe

(
    get_progress_dicts: Callable[[], list[WebElement]],
    iterations: int = 20,
    delay: int | float = 1.0,
    stable_iterations: int = 3,
)

Source from the content-addressed store, hash-verified

498
499
500async def poll_for_stopped_progress(
501 get_progress_dicts: Callable[[], list[WebElement]],
502 iterations: int = 20,
503 delay: int | float = 1.0,
504 stable_iterations: int = 3,
505) -> list[dict]:
506 """Poll for progress dictionaries to stop updating.
507
508 Args:
509 get_progress_dicts: A callable that returns the list of progress dictionary elements.
510 iterations: Maximum number of iterations to poll for.
511 delay: Delay in seconds between iterations.
512 stable_iterations: Number of consecutive iterations with no new progress dictionaries before considering it stopped.
513
514 Returns:
515 The stable list of deserialized progress dicts.
516
517 Raises:
518 TimeoutError: If progress dictionaries keep updating beyond the maximum iterations.
519 """
520 remaining_stable_iterations = stable_iterations
521 last_progress_dicts_content = [p.text for p in get_progress_dicts()]
522 for _ in range(iterations):
523 await asyncio.sleep(delay)
524 progress_dicts_content = [p.text for p in get_progress_dicts()]
525 if progress_dicts_content == last_progress_dicts_content:
526 # Content remains stable, decrement remaining_stable_iterations
527 remaining_stable_iterations -= 1
528 if remaining_stable_iterations <= 0:
529 return [json.loads(t) for t in last_progress_dicts_content]
530 else:
531 # Progress dicts content changed, we must start over counting stable iterations.
532 remaining_stable_iterations = stable_iterations
533 last_progress_dicts_content = progress_dicts_content
534 msg = f"Progress dictionaries kept updating after {iterations} iterations ({iterations * delay} seconds)."
535 raise TimeoutError(msg)
536
537
538def poll_for_token(driver: WebDriver, upload_file: AppHarness) -> str:

Callers 1

test_cancel_uploadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected