可停止线程任务管理器
Project description
可停止线程任务管理器
参考Java线程实现,利用异常中止任务运行
Quick Start
import time
import datetime
from loguru import logger
from StopableThreadJob.job_manager import JobManager
if __name__ == '__main__':
def slow_func( name):
for i in range(5):
logger.info(f"{name} -- {datetime.datetime.now()}")
time.sleep(1)
job_manager = JobManager()
# 删除未添加任务
job_manager.remove_job('2')
for pid in range(6):
logger.info(f"添加任务: {pid}")
job_manager.add_job(target=slow_func, args=(pid,), job_id=f'{pid}')
time.sleep(1)
job_manager.start_job()
# 删除已添加运行中任务
job_manager.remove_job('1')
# 删除已添加未运行中任务
job_manager.remove_job('4')
time.sleep(5)
# 删除运行完成任务
job_manager.remove_job('0')
job_manager.print_current_job()
print(job_manager.job_store)
for i in [0, 1, 2, 4]:
logger.info(f"添加任务: {i}")
job_manager.add_job(target=slow_func, args=(i,), job_id=f'{i}')
job_manager.print_current_job()
job_manager.start_job()
time.sleep(6)
print(job_manager.job_store)
job_manager.print_current_job()
time.sleep(30)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file stopable_thread_job-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: stopable_thread_job-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71ee25afee3d8cdcd3fd4c653ca6f087317a7e92541cb4234e85d748b7191c9e |
|
MD5 | a5cd96d8b537f6406e2c1b885204b76d |
|
BLAKE2b-256 | a191375d1298ce0da33ba97890d70aacdc18d6f5f4178199747efaa1a2494d36 |