簡體   English   中英

任務不運行 Luigi

[英]Task does not run Luigi

我寫了一段簡單的代碼來運行 Luigi 中的任務。 代碼如下:

import luigi

count = 0

class TaskC(luigi.Task):
    def requires(self):
        return None

    def run(self):
        print("Running task C ...")
        global count
        with self.output().open('w') as outfile:
            outfile.write("Finished task C, count = %d", count)
            count += 1
        
    def output(self):
        return luigi.LocalTarget("./logs/task_c.txt")


class TaskB(luigi.Task):
    def requires(self):
        return None

    def run(self):
        print("Running task B ...")
        global count
        with self.output().open('w') as outfile:
            outfile.write("Finished task B, count = %d ...", count)
            count += 1
        
    def output(self):
        return luigi.LocalTarget("./logs/task_b.txt")


class TaskA(luigi.Task):

    def requires(self):
        return [TaskB(), TaskC()]

    def run(self):
        print("Running task A ...")
        global count
        with self.output().open('w') as outfile:
            outfile.write("Finished task A, count = %d ...", count)
            count += 1

    def output(self):
        return luigi.LocalTarget("./logs/task_a.txt")

if __name__ == '__main__':
    print("Start the fisrt luigi app :)")
    luigi.run()

期望:我想運行 TaskA,但 TaskA 需要 TaskB 和 TaskC -> TaskB 和 TaskC 應該在任務 B、C 完成之前和首先運行,然后 TaskA 可以運行

實際:僅運行 TaskA。 其他任務沒有。 登錄控制台:

Start the fisrt luigi app :)
DEBUG: Checking if TaskA() is complete
INFO: Informed scheduler that task   TaskA__99914b932b   has status   DONE
INFO: Done scheduling tasks
INFO: Running Worker with 1 processes
DEBUG: Asking scheduler for work...
DEBUG: Done
DEBUG: There are no more tasks to run at this time
INFO: Worker Worker(salt=382715991, workers=1, host=w10tng, username=tng, pid=2096) was stopped. Shutting down Keep-Alive thread
INFO:
===== Luigi Execution Summary =====

Scheduled 1 tasks of which:
* 1 complete ones were encountered:
    - 1 TaskA()

Did not run any tasks
This progress looks :) because there were no failed tasks or missing dependencies

===== Luigi Execution Summary =====

我曾經運行的命令

python first_luigi_app.py --local-scheduler TaskA

我不知道我是否遺漏了什么! 如果有人可以提供幫助,我們將不勝感激:)

您可以嘗試從任務 B 和任務 C 中刪除 requires 方法,方法是返回 None 它們被跳過。 此外,當使用 f-string 格式化時,它工作正常。 運行: python -m luigi --module l1 TaskA --local-scheduler 其中 l1 是 l1.py(你的代碼的副本)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM