def timeout_thread(queue):
    """Terminate threads by timeout.

    Function need to be run in separate thread. Its designed to terminate
    threads which are running longer then timeout.

    Parent thread will put tuples (thread_ident, deadline) in the queue,
    where `thread_ident` is Thread.ident value of thread to watch, and
    `deadline` is timestamp when thread should be terminated. Also tuple
    (None, None) should be put when all threads are exited and no more
    threads to watch.

    :param queue: Queue object to communicate with parent thread.
    """

    all_threads = collections.deque()
    while True:
        if not all_threads:
            timeout = None
        else:
            thread_ident, deadline = all_threads[0]
            timeout = deadline - time.time()
        try:
            next_thread = queue.get(timeout=timeout)
            all_threads.append(next_thread)
        except (moves.queue.Empty, __HOLE__):
            # NOTE(rvasilets) Empty means that timeout was occurred.
            # ValueError means that timeout lower then 0.
            LOG.info("Thread %s is timed out. Terminating." % thread_ident)
            terminate_thread(thread_ident)
            all_threads.popleft()

        if next_thread == (None, None,):
            return
dataset/ETHPy150Open openstack/rally/rally/common/utils.py/timeout_thread