在没有线程

时间:2017-08-23 12:50:09

标签: python function loops logic

在这段代码中,我试图做的是last_action == 1时,我希望在关闭之前将LED打开8秒钟。同样在last_action == 0时,我希望LED在开机前关闭8秒钟。 LED的开启和关闭由use_door()功能控制。代码运行没有错误。但是当last_action == 0,当LED关闭时,它在开启前不会关闭8秒。它在last_action == 1时工作正常。

last_open_time = None            
last_close_time = None
last_action = -1


def openthedoor(set_accepted_list,set_list_ant_id,set_forbidden_list,set_accepted_list_frozen):
    global last_open_time
    global last_close_time
    global last_action
    should_remain_close = True 
    should_remain_open = False
    if (last_action == 1):
        curr_time = time.time()
        print "this is the last_action" + str(last_action)

        if last_open_time == None:
            last_open_time = time.time()
            print "time passed - " +str(curr_time - last_open_time)

        if (curr_time - last_open_time) < 8:
            should_remain_open = True
            print "should remain open"

    elif (last_action == 0):
        curr_time2 = time.time()
        print "this is the last_action for closing" + str(last_action)

        if last_close_time == None:
            last_close_time = time.time()
            print "time passed on closing-"+str(curr_time2 - last_close_time)

        if (curr_time2 - last_close_time) < 10:
            should_remain_close = True
            print "should_remain_close" 

    if(((len(set_accepted_list) >0) or should_remain_open == True) & (set_forbidden_list == set()) & ((set_accepted_list_frozen == None) or ((set_accepted_list_frozen & set_accepted_list)== set_accepted_list))):
        print"yes,open the gate"
        use_door(1)
        last_close_time = None
    else:
        print"no,close the gate"
        use_door(0)
        last_open_time = None
print "this is for shud remain open in 8 sec" + str(should_remain_open)

0 个答案:

没有答案