Exemplo n.º 1
0
def serve(timeout: int) -> int:
    global g_procs

    completed = []

    for task_name, proc in g_procs.items():
        task = Task(task_name)
        task.reload()
        proc.poll()

        if proc.returncode is not None:
            if proc.returncode:
                if proc.returncode == 126:  # bash error code for "Command invoked cannot execute"
                    task.skip()
                    verbose(1, task.name, 'skipped')

                else:
                    task.fail()
                    verbose(1, task.name, 'failed')

            elif task.once:
                task_name = task.name
                task.delete()
                verbose(1, task_name, 'delete')

            else:
                task.reset()
                verbose(1, task.name, 'reset')

            completed += [task_name]

        elif timeout and task.expired(timeout):
            _terminate_and_fail(task, timeout)
            completed += [task_name]

    for task in completed:
        g_procs[task].stdout.close()
        del g_procs[task]

    return len(g_procs)