
我想在异步任务队列中“执行”图形,类似于celery提供的(因此我可以轮询作业的状态,检索结果等). Celery不提供创建DAG的能力(据我所知)并且能够在所有依赖关系完成后立即执行任务(DAG可能有多个路径,即使一个任务很慢/阻止,有可能继续其他任务等).
有没有简单的例子说明我如何实现这一目标,或者甚至将networkx与芹菜整合?
解决方法 我认为这个功能可能有所帮助:# The graph G is represened by a dictionnary following this pattern: # G = { vertex: [ (successor1: weight1),(successor2: weight2),... ] } def progress ( G,start ): Q = [ start ] # contain tasks to execute done = [ ] # contain executed tasks while len (Q) > 0: # still there tasks to execute ? task = Q.pop(0) # pick up the oldest one ready = True for T in G: # make sure all predecessors are executed for S,w in G[T]: if S == task and and S not in done:# found not executed predecessor ready = False break if not ready : break if not ready: Q.appen(task) # the task is not ready for execution else: execute(task) done.appen(task) # execute the task for S,w in G[task]:# and explore all its successors Q.append(S) 总结 以上是内存溢出为你收集整理的python – Networkx作为任务队列?全部内容,希望文章能够帮你解决python – Networkx作为任务队列?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)