2014-06-21 2 views
0

나는 2 초마다 타이머를 설정하여 setLabel 함수의 값을 업데이트 할 수 있도록 Python 스크립트를 작성하고 있습니다. 그들은 한 번에 한 번씩 업데이트 할 수 있기 때문에 setLabel에 대해 서로 다른 값을 사용하여 타이머를 만들어야합니다. 여기 파이썬에서 타이머를 만드는 법

예를 들면 다음과 같습니다

#set the timer for 2 seconds to update the value in the setlabel 
self.getControl(4202).setLabel("1%") 


#Stop the timer and set the timer again for 2 seconds 
self.getControl(4202).setLabel("8%") 


#Stop the timer and set the timer again for another 2 seconds 
self.getControl(4202).setLabel("16%") 

등등 ...

당신은 내가 나를 한 번에 각각의 값을 업데이트 할 수 있도록 타이머를 만드는 방법을 말해 주시겠습니까?

편집 :이 때 :

# Get the loaded data 
         for channel in tv_elem.findall('channel'): 
          channel_name = 
channel.find('display-name').text 
          for program in channel.findall('programme'): 
           title = program.find('title').text 
           start_time = program.get("start") 
           stop_time = program.get("stop") 
           cur.execute("INSERT INTO programs(channel, 
title, start_date, stop_date)" + " VALUES(?, ?, ?, ?)", [channel_name, 
title, start_time, stop_time]) 
           con.commit() 
           con.close 

           time.sleep(2) 
           #Stop the timer and set the timer again 
for 2 seconds 
           self.getControl(4202).setLabel("8%") 

           time.sleep(2) 
           #Stop the timer and set the timer again 
for another 2 seconds 
           self.getControl(4202).setLabel("16%") 

           time.sleep(2) 
           #Stop the timer and set the timer again 
for another 2 seconds 
           self.getControl(4202).setLabel("24%") 

그것은 나 데이터베이스에 데이터를 기록 할 수 없습니다. 어떤 생각?

+0

누구든지 어떻게 알 수 있습니까 ?????????? –

+1

"나를 내버려 두지 않는다"는 것은 무엇을 의미합니까? 오류? 예외? 코드에서 루프에서 con.close()를 호출하는 것이 이상합니다. 루프 앞뒤로 열거 나 닫을 수 있습니다. – pmod

답변

0

time 모듈의 sleep을 고려하셨습니까?

import time 

time.sleep(2) # probably don't need this one 
#set the timer for 2 seconds to update the value in the setlabel 
self.getControl(4202).setLabel("1%") 


time.sleep(2) 
#Stop the timer and set the timer again for 2 seconds 
self.getControl(4202).setLabel("8%") 


time.sleep(2) 
#Stop the timer and set the timer again for another 2 seconds 
self.getControl(4202).setLabel("16%") 
+0

대단히 감사합니다. 어떻게 sqlite3 데이터베이스에 데이터를 저장할 때 이러한 코드를 사용하여 작업 할 수 있습니까? 내가 데이터베이스 아래에서 이러한 코드를 사용하면 작업이 중단됩니다. 어떤 생각? –

+0

답변을 기다리고 있습니다. 게시 한 코드를 사용하면 데이터를 데이터베이스에 쓸 수 없습니다. 이'time.sleep (5)'코드를 제거하면 잘 동작합니다. 어떤 생각? –

+0

아마도 트랜잭션을 단일 트랜잭션으로 그룹화하는 방법을 알아야 할 필요가 있습니다.이 방법으로 sleep()을 사용하면 아마도 좋지 않은 해결 방법 일 수 있습니다. 당신이 아주 명확한 질문을하지 않은 것처럼 보입니다. –

0

선택할 수있는 Python 스케줄링 라이브러리가 몇 가지 있습니다. Celery는 예약 된 작업을 지원하는 매우 강력한 동기 작업 대기열 및 메시지 시스템입니다.

고급 Python 스케줄러 (APScheduler)를 사용해 본 적이 있습니까 나는 그것을 좋아한다. 함수를 호출 할 수 있습니다

@sched.interval_schedule(minutes=3) 
def timed_job(): 
    print 'This job is run every three minutes.' 
관련 문제