用于管理后台任务(异步)的作业计划程序。
aiojobs的Python项目详细描述
用于管理后台任务的作业计划程序(异步)
库为调度 异步应用程序。
安装
$ pip3 install aiojobs
用法示例
importasyncioimportaiojobsasyncdefcoro(timeout):awaitasyncio.sleep(timeout)asyncdefmain():scheduler=awaitaiojobs.create_scheduler()foriinrange(100):# spawn jobsawaitscheduler.spawn(coro(i/10))awaitasyncio.sleep(5.0)# not all scheduled jobs are finished at the moment# gracefully close spawned jobsawaitscheduler.close()asyncio.get_event_loop().run_until_complete(main())
与aiohttp.web集成
fromaiohttpimportwebfromaiojobs.aiohttpimportsetup,spawnasyncdefhandler(request):awaitspawn(request,coro())returnweb.Response()app=web.Application()app.router.add_get('/',handler)setup(app)
或者只是
fromaiojobs.aiohttpimportatomic@atomicasyncdefhandler(request):returnweb.Response()
有关详细信息,请阅读文档:https://aiojobs.readthedocs.io
通信信道
aio libsgoogle组:https://groups.google.com/forum/#!forum/aio-libs
欢迎在这里发表你的问题和想法。
gitter聊天https://gitter.im/aio-libs/Lobby
我们支持Stack Overflow。 请在问题中添加python asyncio或aiohttp标记。