初回コミット
This commit is contained in:
commit
035d94aac7
23
timeSchedule.py
Normal file
23
timeSchedule.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
|
class TaskScheduler:
|
||||||
|
def __init__(self):
|
||||||
|
self._thread = threading.Thread(target=self._run_task)
|
||||||
|
self._thread.start()
|
||||||
|
|
||||||
|
def _run_task(self):
|
||||||
|
while True:
|
||||||
|
print("Task is running...")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
# インスタンスを作成し、スレッドを起動
|
||||||
|
scheduler = TaskScheduler()
|
||||||
|
|
||||||
|
# インスタンスを破棄(しかしスレッドは続行)
|
||||||
|
# del scheduler
|
||||||
|
|
||||||
|
# メインスレッドは他の作業を続ける
|
||||||
|
for _ in range(5):
|
||||||
|
print("Main thread is working...")
|
||||||
|
time.sleep(1)
|
Loading…
x
Reference in New Issue
Block a user