tests/task/simulate.py
def process_task_pool(pool, max_wait_time=5, sleep_interval=1):
    '''
    Runs the provided task `Pool` until all tasks have finished.

    The `max_wait_time` indicates the (minimum) amount of seconds that must
    pass until an exception is raised. If set to `0`, no timeout will occur.

    This will attempt to recover from potential pitfalls (i.e. unintended
    behaviour), so it hopefully won't block indefinitely.

    Raises a `TimeoutError` if run time exceeds `max_wait_time` seconds.
    '''
    if not isinstance(max_wait_time, (int, float)):
        raise TypeError('max wait time must be a number: %r' % (max_wait_time))
    if not isinstance(pool, Pool):
        raise TypeError('task pool must be a Pool: %r' % (pool))

    no_timeout = (max_wait_time == 0)
    if no_timeout:
        raise NotImplementedError

    logger.debug(
        'waiting %r seconds in %r second intervals for tasks to complete',
        max_wait_time, sleep_interval,
    )

    # not the most elegant solution, but fairly reliable
    current_wait_time = 0
    while current_wait_time < max_wait_time:
        if pool.queue.empty():
            logger.debug('task pool empty! returning')
            return

        logger.debug('tasks are still pending, waiting %rs', sleep_interval)
        time.sleep(sleep_interval)
        current_wait_time += sleep_interval

    if current_wait_time >= max_wait_time:
        raise TimeoutError('run time exceeded %r seconds' % (max_wait_time))

    Runs the provided task `Pool` until all tasks have finished.

    The `max_wait_time` indicates the (minimum) amount of seconds that must
    pass until an exception is raised. If set to `0`, no timeout will occur.

    This will attempt to recover from potential pitfalls (i.e. unintended
    behaviour), so it hopefully won't block indefinitely.

    Raises a `TimeoutError` if run time exceeds `max_wait_time` seconds.
    
Runs the provided task `Pool` until all tasks have finished.
The `max_wait_time` indicates the (minimum) amount of seconds that must
pass until an exception is raised. If set to `0`, no timeout will occur.

This will attempt to recover from potential pitfalls , so it hopefully won't block indefinitely.

Raises a `TimeoutError` if run time exceeds `max_wait_time` seconds.
Runs the provided task ` Pool ` until all tasks have finished . The ` max_wait_time ` indicates the ( minimum ) amount of seconds that must pass until an exception is raised . If set to ` 0 ` no timeout will occur . This will attempt to recover from potential pitfalls so it hopefully won ' t block indefinitely . Raises a ` TimeoutError ` if run time exceeds ` max_wait_time ` seconds .
def process_task_pool(pool, max_wait_time=5, sleep_interval=1):
    if not isinstance(max_wait_time, (int, float)):
        raise TypeError('max wait time must be a number: %r' % (max_wait_time))
    if not isinstance(pool, Pool):
        raise TypeError('task pool must be a Pool: %r' % (pool))
    no_timeout = (max_wait_time == 0)
    if no_timeout:
        raise NotImplementedError
    logger.debug(
        'waiting %r seconds in %r second intervals for tasks to complete',
        max_wait_time, sleep_interval,
    )
    current_wait_time = 0
    while current_wait_time < max_wait_time:
        if pool.queue.empty():
            logger.debug('task pool empty! returning')
            return
        logger.debug('tasks are still pending, waiting %rs', sleep_interval)
        time.sleep(sleep_interval)
        current_wait_time += sleep_interval
    if current_wait_time >= max_wait_time:
        raise TimeoutError('run time exceeded %r seconds' % (max_wait_time))
def process_task_pool ( pool , max_wait_time = 5 , sleep_interval = 1 ) : if not isinstance ( max_wait_time , ( int , float ) ) : raise TypeError ( 'max wait time must be a number: %r' % ( max_wait_time ) ) if not isinstance ( pool , Pool ) : raise TypeError ( 'task pool must be a Pool: %r' % ( pool ) ) no_timeout = ( max_wait_time == 0 ) if no_timeout : raise NotImplementedError logger . debug ( 'waiting %r seconds in %r second intervals for tasks to complete' , max_wait_time , sleep_interval , ) current_wait_time = 0 while current_wait_time < max_wait_time : if pool . queue . empty ( ) : logger . debug ( 'task pool empty! returning' ) return logger . debug ( 'tasks are still pending, waiting %rs' , sleep_interval ) time . sleep ( sleep_interval ) current_wait_time += sleep_interval if current_wait_time >= max_wait_time : raise TimeoutError ( 'run time exceeded %r seconds' % ( max_wait_time ) )
Runs the provided task `Pool` until all tasks have finished.
Runs the provided task ` Pool ` until all tasks have finished .
'''
    Runs the provided task `Pool` until all tasks have finished.

    The `max_wait_time` indicates the (minimum) amount of seconds that must
    pass until an exception is raised. If set to `0`, no timeout will occur.

    This will attempt to recover from potential pitfalls (i.e. unintended
    behaviour), so it hopefully won't block indefinitely.

    Raises a `TimeoutError` if run time exceeds `max_wait_time` seconds.
    ''' # not the most elegant solution, but fairly reliable
pool
max_wait_time
sleep_interval