示例#1
0
def test_stages():
    # sem is used to reduce number of running instances of mugen
    semaphore = asyncio.Semaphore(max_parallel_matches)
    stages_path = Match.mugen_folder + 'stages\\'
    working_path = Match.mugen_folder + 'working_stages\\'
    running_tasks = set()

    try:
        os.mkdir(working_path)
    except FileExistsError:
        pass

    def done_cb(f):
        semaphore.release()
        running_tasks.remove(f)
        match = f.result()
        if match:
            move_stage(match.stage, working_path)

    for stage in list(get_stages(stages_path)):
        yield from semaphore
        match = Match(stage=stage)
        task = asyncio.Task(match_in_thread(match))
        task.add_done_callback(done_cb)
        running_tasks.add(task)

        # this sleep is required to ensure the window gets focus.
        # without gaining focus, the game will never start
        yield from asyncio.sleep(.5)

    # wait for all all processes to complete or be killed
    yield from asyncio.wait(running_tasks)
示例#2
0
def write_stages(fp, stages_path):
    print("{0}".format(stages_header), file=fp)
    for stage in get_stages(stages_path):
        path = stage.path
        print("{0}".format(path), file=fp)