Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Networkx作为任务队列?_Python_Celery_Networkx_Task Queue_Directed Acyclic Graphs - Fatal编程技术网

Python Networkx作为任务队列?

Python Networkx作为任务队列?,python,celery,networkx,task-queue,directed-acyclic-graphs,Python,Celery,Networkx,Task Queue,Directed Acyclic Graphs,我在networkx中有一个有向无环图。每个节点代表一个任务,节点的前辈是任务依赖项(在其依赖项执行之前,给定任务无法执行) 我希望在异步任务队列中“执行”该图,类似于Cellery提供的功能(以便我可以轮询作业的状态、检索结果等)。芹菜没有提供创建DAG的能力(据我所知),并且在所有依赖项完成后立即转移到任务是至关重要的(DAG可能有多条路径,即使一个任务很慢/阻塞,也可能转移到其他任务等) 关于如何实现这一点,或者甚至将networkx与芹菜集成,是否有一些简单的例子?我认为此功能可能会有所

我在
networkx
中有一个有向无环图。每个节点代表一个任务,节点的前辈是任务依赖项(在其依赖项执行之前,给定任务无法执行)

我希望在异步任务队列中“执行”该图,类似于
Cellery
提供的功能(以便我可以轮询作业的状态、检索结果等)。芹菜没有提供创建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)

您可以使用的一个库是。它允许您定义任务图,然后以多线程/多进程的方式执行这些任务。它避免了重新运行结果已经是最新的任务,类似于make程序

要执行networkx图形,您需要迭代中的所有节点,收集每个节点的IMemidate依赖项,然后调用
task\u graph.add\u task
。此函数将返回新添加任务的句柄,这使您可以将其用作后续添加任务的依赖项(这就是为什么节点迭代顺序很重要的原因)


有关其他解决方案,请参见。

您可能正在搜索的内容称为dask:您从未执行过任何任务。