35 lines
625 B
Python
35 lines
625 B
Python
|
#!/usr/bin/env python
|
||
|
# -*- coding: UTF-8 -*-
|
||
|
|
||
|
import sys
|
||
|
sys.path.append('../..')
|
||
|
import task
|
||
|
import time
|
||
|
|
||
|
task_num = 0
|
||
|
|
||
|
|
||
|
def time_print(txt):
|
||
|
sys.stdout.write(time.asctime() + ': ' + txt + '\n')
|
||
|
|
||
|
|
||
|
def hello(rt, name):
|
||
|
global task_num
|
||
|
task_num += 1
|
||
|
if task_num >= 5:
|
||
|
rt.stop()
|
||
|
tn = task_num
|
||
|
time_print("(Task %d) Hello %s!" % (tn, name))
|
||
|
time.sleep(3.8)
|
||
|
time_print("(Task %d) Ende!" % (tn))
|
||
|
|
||
|
|
||
|
print("task.periodic example:\n----------------------")
|
||
|
pt = task.periodic(2, hello, "from periodic example")
|
||
|
pt.run()
|
||
|
try:
|
||
|
time_print("starting...")
|
||
|
pt.join()
|
||
|
finally:
|
||
|
pt.stop()
|