#coding=utf-8
import threading
import logging
import time
# 多任务多线程任务管理类
class task_manage():
# name 任务名称
# task_func 任务函数指针
# task_args 任务函数参数,默认空
# check_func 任务是否执行完检测函数指针,返回true表示还有任务没有执行,默认调用自身的runtimes_control函数
# check_args 任务检测函数指针参数,默认空
# max_thread_count 最大线程数
# run_time 任务运行次数,设置check_func后,该参数无效
def __init__(self,name,task_func,task_args=(),check_func=none,check_args=(),max_thread_count=1,run_time=1):
self._is_finished = false
self._task_func = task_func
self._task_args = task_args
self._max_thread_count = max_thread_count
self._threads = []
self._name = name
self._check_args = check_args
self._run_time = run_time
self._task_index = 0
if check_func is none:
self._check_func = self.runtimes_control
self._check_args = ()
else:
self._check_func = check_func
# 任务运行次数控制函数
def runtimes_control(self):
if self._run_time > 0:
self._run_time -= 1
return true
return false
# 清除已退出线程
def clear_exit_threads(self):
for t in self._threads[:]:
if not t.is_alive() :
self._threads.remove(t)
# 运行任务
def run(self):
while(len(self._threads)
用户登录
还没有账号?立即注册
用户注册
投稿取消
| 文章分类: |
|
还能输入300字
上传中....
依的那个旧