2012-08-26 3 views
-1

나는 뭔가를해야한다는 것을 상기시키기 위해 특정 시간에 윈도우 박스 팝업을 만드는 파이썬 프로그램을 만들려고 노력 중이다. 문제는 while 루프가 파이썬 충돌을 일으키고, 파이썬이 while 루프없이 시간을 확인하도록하는 방법이 있습니까?while 루프가없는 파이썬 체크 시간

while 1: 
    gettime = time.strftime("%H:%M", time.localtime()) 
    gettime.replace(':','.') 

    if gettime in tasks.keys(): 
     tasks[gettime] = dowat 
     ctypes.windll.user32.MessageBoxW(0,u'ALERT!', dowat, 0) 
     time.sleep(10) 
     SendKeys.SendKeys(""" 
       {LWIN} 
       l 
       """) 

루프의 끝에서 파이썬 수면을 만들려고했지만 여전히 고정되어 있습니다.

+0

문제는 'while'루프가 아닙니다. 추락합니까, 아니면 동결합니까? 문제가 발생하면 어떤 메시지를 더 구체적으로 얻을 수 있습니까? – kindall

+1

그냥 [예약 된 작업] (http://support.microsoft.com/kb/308569)에 넣지 않는 이유는 무엇입니까? – katrielalex

+0

저는 이것을 작은 프로젝트로하고 싶었습니다. 그냥 멈추어 응답을 멈 춥니 다. – user1492032

답변

1

당신은 틀린 길로 가고 있습니다 ... 당신은 while 루프가 필요 없습니다. 당신이해야 할 일은 당신의 현재 시간을 얻고 시차를 없애는 것입니다. 그럼 시간 만 전화하면됩니다. 잠깐 .

다음과 같은 오래된 파이썬 코드가 있습니다. 청소/제거해야 할 물건이 주위에 있었으므로 100 % 작동하지 않을 수 있습니다.

import time 
import datetime 

CurrentTime = datetime.datetime.now() 

exec_time = "18:00" 

val = datetime.datetime.strptime(exec_time, "%H:%M") 
val = datetime.datetime(year=CurrentTime.year, month=CurrentTime.month, day=CurrentTime.day, hour=val.hour, minute=val.minute) 

if (val > CurrentTime): 
    print "val = ", val 
    val = datetime.datetime(year=CurrentTime.year, month=CurrentTime.month, day=CurrentTime.day, hour=val.hour, minute=val.minute) - CurrentTime #Calculate dif. 

    time.sleep(val.seconds) #Sleep to next event 
+2

[datetime.replace()를 사용할 수 있으며 val.total_seconds();를 사용해야합니다. threading.Timer()는 컴퓨터가 최대 절전 모드/다시 시작되는 경우 time.sleep()보다 자연스러운 동작을 생성 할 수 있습니다.] (http://stackoverflow.com/a/12015233/4279) – jfs