Ejemplo n.º 1
0
def tasks_runner(subjects_path,
                 tasks_dict,
                 one=None,
                 dry=False,
                 count=5,
                 time_out=None,
                 **kwargs):
    """
    Function to run a list of tasks (task dictionary from Alyx query) on a local server
    :param subjects_path:
    :param tasks_dict:
    :param one:
    :param dry:
    :param count: maximum number of tasks to run
    :param time_out: between each task, if time elapsed is greater than time out, returns (seconds)
    :param kwargs:
    :return: list of dataset dictionaries
    """
    if one is None:
        one = ONE()
    import time
    tstart = time.time()
    c = 0
    last_session = None
    all_datasets = []
    for tdict in tasks_dict:
        # if the count is reached or if the time_out has been elapsed, break the loop and return
        if c >= count or (time_out and time.time() - tstart > time_out):
            break
        # reconstruct the session local path. As many jobs belong to the same session
        # cache the result
        if last_session != tdict['session']:
            ses = one.alyx.rest('sessions',
                                'list',
                                django=f"pk,{tdict['session']}")[0]
            session_path = Path(subjects_path).joinpath(
                Path(ses['subject'], ses['start_time'][:10],
                     str(ses['number']).zfill(3)))
            last_session = tdict['session']
        if dry:
            print(session_path, tdict['name'])
        else:
            task, dsets = tasks.run_alyx_task(tdict=tdict,
                                              session_path=session_path,
                                              one=one,
                                              **kwargs)
            if dsets:
                all_datasets.extend(dsets)
                c += 1
    return all_datasets
Ejemplo n.º 2
0
def tasks_runner(subjects_path,
                 tasks_dict,
                 one=None,
                 dry=False,
                 count=5,
                 **kwargs):
    """
    Function to run a list of tasks (task dictionary from Alyx query) on a local server
    :param subjects_path:
    :param tasks_dict:
    :param one:
    :param dry:
    :param kwargs:
    :return: list of dataset dictionaries
    """
    if one is None:
        one = ONE()

    c = 0
    last_session = None
    all_datasets = []
    for tdict in tasks_dict:
        if c >= count:
            break
        # reconstruct the session local path. As many jobs belong to the same session
        # cache the result
        if last_session != tdict['session']:
            ses = one.alyx.rest('sessions',
                                'list',
                                django=f"pk,{tdict['session']}")[0]
            session_path = Path(subjects_path).joinpath(
                Path(ses['subject'], ses['start_time'][:10],
                     str(ses['number']).zfill(3)))
            last_session = tdict['session']
        if dry:
            print(session_path, tdict['name'])
        else:
            task, dsets = tasks.run_alyx_task(tdict=tdict,
                                              session_path=session_path,
                                              one=one,
                                              **kwargs)
            if dsets:
                all_datasets.extend(dsets)
                c += 1
    return all_datasets