python - 如何在运行 local-scheduler 时创建 Luigi 依赖关系图

标签 python

我已经在luigi框架内实现了一些任务,现在我想可视化依赖关系图。

我的同事指示我开始 luigid

luigid mkdir -p luigi;--background --logdir luigi --state-path luigi/state --address 0.0.0.0 --port 32145

之后,我可以在 chrome 浏览器 localhost:32145 中看到任务可视化工具

然后我运行 luigi 任务

python luigi_scheduler.py --local-scheduler

luigi_scheduler 通过以下行运行任务

luigi.run(main_task_cls = someTaskA)

然后我收到以下消息,任务完成。然而,任务可视化工具上什么也没有出现。

DEBUG: Checking if get_usr_activity_all() is complete
/usr/local/lib/python2.7/dist-packages/luigi/task.py:433: UserWarning: Task get_usr_activity_all() without outputs has no custom complete() method
warnings.warn("Task %r without outputs has no custom complete() method" % self)
INFO: Scheduled get_usr_activity_all() (PENDING)
DEBUG: Checking if get_usr_hw(n=33000) is complete
INFO: Scheduled get_usr_hw(n=33000) (DONE)
DEBUG: Checking if get_usr_login(n=33000) is complete
INFO: Scheduled get_usr_login(n=33000) (DONE)
INFO: Done scheduling tasks
INFO: Running Worker with 1 processes
DEBUG: Asking scheduler for work...
DEBUG: Pending tasks: 1
INFO: [pid 16937] Worker Worker(salt=675435319, host=ubuntu, username=junchen, pid=16937) running   get_usr_activity_all()
INFO: [pid 16937] Worker Worker(salt=675435319, host=ubuntu, username=junchen, pid=16937) done      get_usr_activity_all()
DEBUG: 1 running tasks, waiting for next task to finish
DEBUG: Asking scheduler for work...
INFO: Done
INFO: There are no more tasks to run at this time
INFO: Worker Worker(salt=675435319, host=ubuntu, username=junchen, pid=16937) was stopped. Shutting down Keep-Alive thread

最佳答案

我知道这是一个老问题,但对于任何登陆那里的人来说,实际上有一种方法可以独立于任何调度程序来可视化任务的依赖关系树,由 luigi.tools.deps_tree 提供。模块。

假设您运行 luigi 时:

luigi.run(main_task_cls = someTaskA)

您可以通过在运行前添加以下内容来让您的脚本打印 someTaskA 的依赖树:

import luigi.tools.deps_tree as deps_tree

print(deps_tree.print_tree(someTaskA))

这将在控制台打印类似这样的内容:

└─--[Foo-{} (PENDING)]
   |--[Bar-{'num': '0'} (PENDING)]
   |  |--[Bar-{'num': '4'} (PENDING)]
   |  └─--[Bar-{'num': '5'} (PENDING)]
   |--[Bar-{'num': '1'} (PENDING)]
   └─--[Bar-{'num': '2'} (PENDING)]
      └─--[Bar-{'num': '6'} (PENDING)]
         |--[Bar-{'num': '7'} (PENDING)]
         |  |--[Bar-{'num': '9'} (PENDING)]
         |  └─--[Bar-{'num': '10'} (PENDING)]
         |     └─--[Bar-{'num': '11'} (PENDING)]
         └─--[Bar-{'num': '8'} (PENDING)]
            └─--[Bar-{'num': '12'} (PENDING)]

其中 FooBar 是任务名称,dicts {'num': 'x'} 是这些任务的参数.

我发现这特别有用,特别是对于调试具有大量参数的复杂工作流程。

关于python - 如何在运行 local-scheduler 时创建 Luigi 依赖关系图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27617082/

相关文章:

python - Tornado mysql : how to get size of cursor

python - Seaborn 箱线图 : TypeError: unsupported operand type(s) for/: 'str' and 'int'

python - 身份验证失败,代码为 32

python - 使用 NumPy asarray 方法将列表转换为数组

python - 在 pandas 中组合具有重叠索引的不同列

python - 使用python3.5的aiohttp查询get URL的参数

python - 使用 multiprocessing.pool.Pool 初始化并行处理无限期卡住

python - 更改/更新 strip 订阅 (django) 的问题

python - 无法使用 numpy 从数组 python 中删除列

python - 如何测量python中代码行之间的时间?