Esempio n. 1
0
async def test_empty_scheduler_lifecycle(timer):
    with timer, async_timeout.timeout(1):
        scheduler = Scheduler()
        assert scheduler.empty()
        await scheduler.wait()
        assert scheduler.empty()
        await scheduler.close()
        assert scheduler.empty()
    assert timer.seconds < CODE_OVERHEAD
Esempio n. 2
0
async def _wait_for_depletion(
    *,
    signaller: asyncio.Condition,
    scheduler: aiotasks.Scheduler,
    settings: configuration.OperatorSettings,
    streams: Streams,
) -> None:

    # Notify all the workers to finish now. Wake them up if they are waiting in the queue-getting.
    for stream in streams.values():
        await stream.backlog.put(EOS.token)

    # Wait for the queues to be depleted, but only if there are some workers running.
    # Continue with the tasks termination if the timeout is reached, no matter the queues.
    # NB: the scheduler is checked for a case of mocked workers; otherwise, the streams are enough.
    async with signaller:
        try:
            await asyncio.wait_for(
                signaller.wait_for(lambda: not streams or scheduler.empty()),
                timeout=settings.batching.exit_timeout)
        except asyncio.TimeoutError:
            pass

    # The last check if the termination is going to be graceful or not.
    if streams:
        logger.warning(
            f"Unprocessed streams left for {list(streams.keys())!r}.")