卡维顿io

qaviton-io的Python项目详细描述


卡维顿IO

logo
versionlicenseopen issuesdownloadscode size

Qaviton IO
是一个具有简单API的包,利用python的异步和多处理
使许多异步操作能够快速执行。在

安装

pip install qaviton-io -U

要求

  • Python 6.3+

特点

  • 异步任务管理器
  • 流程任务管理器
  • 任务记录器

使用

异步管理器 ^{pr2}$

流程经理:

"""make sure your tasks are defined at the module level,so they can be pickled by multiprocessing"""fromtimeimporttimefromrequestsimportgetfromqaviton_io.typesimportTasksfromqaviton_ioimportProcessManager,taskfromtracebackimportformat_exc# now we make some tasks# this is a nested task# we don't want to handle any exceptions# so in case of failure the parent will not proceed@task()deftask1(url):r=get(url)r.raise_for_status()# this is the prent task# we want to handle all exceptions# so in case of failure the next task will execute@task(exceptions=Exception)defmulti_task():forurlin["https://qaviton.com","https://qaviton.co.il",# make sure you enter a valid address"https://qaviton.com1",# make sure you enter a valid address]:task1(url)# let's create a function to execute tasksdefexecute_tasks(tasks:Tasks,timeout):manager=ProcessManager()t=time()try:manager.run_until_complete(tasks,timeout=timeout)timed_out=NoneexceptTimeoutError:timed_out=format_exc()t=time()-tmanager.report()print(f'took {round(t,3)}s\n')manager.log.clear()returntimed_out# now all that's left is to run the tasksif__name__=="__main__":timeouts=[execute_tasks([multi_taskfor_inrange(1)],timeout=3),execute_tasks([multi_taskfor_inrange(20)],timeout=6),execute_tasks([multi_taskfor_inrange(80)],timeout=9),]fortimeoutintimeouts:iftimeout:print(timeout)

注意事项:

  • 性能好、使用方便
    您可能应该坚持使用AsyncManager

  • ProcessManager使用异步操作和多处理。
    它跨CPU分配任务,并使用AsyncManager执行这些任务
    如果您想要最大的效率,您应该考虑使用ProcessManager

  • ProcessManager使用多处理模块
    并应相应地处理其限制和限制

  • ProcessManager很容易卡住,
    使用时一定要使用超时

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
异常如何在java中优雅地处理FileNotFoundexception   java线程卡在BlockingQueue上。无缘无故   类网格程序w/java   StrutsJava:动态应用Velocity脚本   java在运行时重写/禁用方面   java Apache POI无法正确读取Excel单元格中的秒数   具有不同用户权限的Java文件夹/文件创建   java我可以检查Firebase ValueEventListener onDataChanged是否已被调用吗?   尽管获得了用户权限,java Android开发文件权限仍被拒绝   java如何使用JPA映射map<EnumType,Double>?   java是否使用UI线程显示toast消息?   JAVAlang.IllegalArgumentException:不支持的元素:rss   java Android setRequestedOrientation活动和视图生命周期   安卓如何在Java中定义支票盒?   在Java中,对于大输入,字符串解析长期失败   使Java在XP中按计划任务运行读取env用户变量时出现问题   任务“:workflowsjava:NodeDriver”的梯度执行失败。main()   java如何检测是否只设置了部分属性?   在客户端web服务上使用JBossWS时,java无法找到/更改log4j的默认配置   java LibGDX写入文本文件并接收各种错误