f336f31c56fd8cfe0847240786abe6f6607dcd25,sos/sos_task.py,,check_task,#Any#,189

Before Change


def check_task(task):
    status_file =  os.path.join(os.path.expanduser("~"), ".sos", "tasks", task + ".status")
    res_file =  os.path.join(os.path.expanduser("~"), ".sos", "tasks", task + ".res")
    if not os.path.isfile(status_file):
        return "pending"
    elif os.path.isfile(res_file):
        try:
            with open(res_file, "rb") as result:
                res = pickle.load(result)
            if res["succ"] == 0:
                return "completed"
            else:
                return "failed"
        except Exception as e:
            return "failed"
    // dead?
    start_stamp = os.stat(status_file).st_mtime
    elapsed = time.time() - start_stamp
    if elapsed < 0:
        env.logger.warning("{} is created in the future. Your system time might be problematic".format(status_file))

After Change


    // frozen:        if with a new status file that has not been updated
    // 
    //
    task_file =  os.path.join(os.path.expanduser("~"), ".sos", "tasks", task + ".task")
    status_file =  os.path.join(os.path.expanduser("~"), ".sos", "tasks", task + ".status")
    res_file =  os.path.join(os.path.expanduser("~"), ".sos", "tasks", task + ".res")

    if os.path.isfile(res_file):
        new_res = os.path.getmtime(task_file) <= os.path.getmtime(res_file)
        try:
            with open(res_file, "rb") as result:
                res = pickle.load(result)
            if res["succ"] == 0:
                if new_res:
                    return "completed"
                else:
                    return "completed-old"
            else:
                if new_res:
                    return "failed"
                else:
                    return "failed-old"
        except Exception as e:
            return "failed"
    try:
        if not os.path.isfile(status_file) or os.path.getmtime(status_file) < os.path.getmtime(res_file):
            return "pending"
    except:
        // there is a slight chance that the old res_file is removed
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 8

Instances


Project Name: vatlab/SoS
Commit Name: f336f31c56fd8cfe0847240786abe6f6607dcd25
Time: 2017-02-26
Author: ben.bog@gmail.com
File Name: sos/sos_task.py
Class Name:
Method Name: check_task


Project Name: BYU-PCCL/holodeck
Commit Name: 89587cdd03d34055b013cc983357b10cc4b2e82c
Time: 2018-08-07
Author: joshua.greaves@gmail.com
File Name: holodeck/util.py
Class Name:
Method Name: get_holodeck_path


Project Name: vatlab/SoS
Commit Name: a1af2977c50399f58726182cd9481a6770c115ac
Time: 2017-03-30
Author: ben.bog@gmail.com
File Name: sos/sos_task.py
Class Name:
Method Name: check_task