与屈肌交互的助手库
flexes-lib的Python项目详细描述
弯曲库
flexes客户端库
依赖性
对于异步任务执行,需要python>;=3.5。
使用一目了然
通过api同步运行任务
fromflexes_lib.jobimportrun_taskmessage={'service':'echo-test','test':True}result=run_task(message)print(result['status'])# active
还支持异步任务
fromasyncioimportget_event_loopfromflexes_lib.async_jobimportrun_taskmessage={'service':'echo-test','test':True}result=loop.run_until_complete(run_task(message))print(result['status'])# active
异步任务的好处是可以并行运行它们。 此示例并行提交三个作业,然后等待这三个作业 在返回结果之前完成。
fromasyncioimportgather,get_event_loopfromflexes_lib.async_jobimportrun_taskm1={'service':'echo-test','test':True}m2={'service':'echo-test','test':True}m3={'service':'echo-test','test':True}results=loop.run_until_complete(gather(run_task(m1),run_task(m2),run_task(m3)))print([result['status']forresultinresults])# ['active', 'active', 'active']