python的干净简单的任务并发性。
runium的Python项目详细描述
runium
runium是一个python库,它使编写非阻塞代码变得容易, 异步任务。
您可以随意添加新任务,选择何时和如何执行它们 threads或processs并附加回调,以便在 任务已完成运行。将这些任务运行一次或定期,或计划为 在特定时间运行它们。
runium的目的是做这些简单,容易和干净的,最少 代码没有更改。只需要一行代码。
功能
- concurrency:在自己的线程或进程中运行任务一次或多次。
- 重复:以偶数时间间隔定期运行任务。在一定的时间内可以选择。
- 调度:在特定日期和时间运行任务。
- callbacks:runium任务可以接受在任务完成运行时执行的回调函数。
- 简单性和可读性:在一行易于阅读的代码中完成以上所有操作。
安装
runium分布在pypi上。最好的安装方法是使用pip:
$ pip install runium
快速启动
fromrunium.coreimportRunium# Initialize Runiumrn=Runium()# Or you may want to run your tasks in Processesrn=Runium(mode='multiprocessing')# Create a taskasync_task=rn.new_task(task)# Attach callbacks (Check the documentation for callbacks)async_task.on_finished(callback)# or you can be more flexible...async_task.on_success(s_callback).on_error(e_callback)# Run it. This will return a future object.future=async_task.run()# Or if you want to run it multiple timesfuture=async_task.run(times=3)# Or maybe run it 3 times every 1 hourfuture=async_task.run(every='1 hour',times=3)# Or tell Runium to start the task in a specific timefuture=async_task.run(start_in='5 hours')# Then you can wait for the result.future.result()# Of course you can do all these in one line :)rn.new_task(task).run(every='1 second',times=3).result()