可停止线程任务管理器
参考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)
Metadata
Release files for stopable-thread-job 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stopable_thread_job-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for stopable_thread_job-1.0.1-py3-none-any.whl |
Release files / stopable_thread_job-1.0.1-py3-none-any.whl
| Download URL | stopable_thread_job-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71ee25afee3d8cdcd3fd4c653ca6f087317a7e92541cb4234e85d748b7191c9e
|
|
BLAKE2b-256 checksum How to use checksums |
a191375d1298ce0da33ba97890d70aacdc18d6f5f4178199747efaa1a2494d36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.7
|
Security for stopable-thread-job 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.