서브 클래스가 서브 클래스 인 서브 클래스 threading.Thread
을 작성하면 이런 문제가 발생한다고 생각합니다. 거기에서 수행 할 기능으로 run
메소드를 겹쳐 쓰면이 경우 목록에 항목이 추가됩니다. 그런 다음 main
에서 해당 스레드를 시작한 후 sleep
을 호출합니다. 클래스는 다음과 같이 보일 것이다 :
class ListBuilder(threading.Thread):
def__init__(self):
super().__init__()
self._finished = False
self.lst = []
def get_data():
# This is the data retrieval function
# It could be imported in, defined outside the class, or made static.
def run(self):
while not self._finished:
self.lst.append(self.get_data())
def stop(self):
self._finished = True
귀하의 main
다음 보일 것이다 뭔가 지금
import time
if __name__ == '__main__':
lb = ListBuilder()
lb.start()
time.sleep(120) # sleep for 120 seconds, 2 minutes
lb.stop()
time.sleep(.1) # A time buffer to make sure the final while loop finishes
# Depending on how long each while loop iteration takes,
# it may not be necessary or it may need to be longer
do_stuf(lb.lst) # performs actions on the resulting list
처럼, 당신이 할 일은 0시 19분하고 그것을 실행하려면 Windows 작업 스케줄러를 사용하다 설정해야합니다.
대단히 감사합니다! 이것은 내가 찾고 있었던 대답이었다! :) – Andres123