за исключением того, что он не работает с luigi.build

#python #luigi

Вопрос:

Я использую Luigi 3.0.2, python 3.7.9. Плагин sentry-sdk использует excepthook для уведомления об исключениях, но у меня возникают проблемы с уведомлением, когда в задаче возникает исключение.

sys.excepthook событие не работает со следующим кодом:

 import sys
import time
import luigi


class TaskA(luigi.Task):
    def complete(self):
        return False

    def run(self):
        raise RuntimeError("Something")


def my_excepthook(type, value, traceback):
    print("-------")
    print(value)
    print("-------")


sys.excepthook = my_excepthook

luigi.build(
    tasks=[TaskA()],
    local_scheduler=True,
)
time.sleep(4)
 

Ожидаемый результат: результат RuntimeError("Something")

Фактический:

 DEBUG: Checking if TaskA() is complete
INFO: Informed scheduler that task   TaskA__99914b932b   has status   PENDING
INFO: Done scheduling tasks
INFO: Running Worker with 1 processes
DEBUG: Asking scheduler for work...
DEBUG: Pending tasks: 1
INFO: [pid 25018] Worker Worker(salt=070924467, workers=1, host=Mac-r0077, username=sh.hoshino, pid=25018) running   TaskA()
ERROR: [pid 25018] Worker Worker(salt=070924467, workers=1, host=Mac-r0077, username=sh.hoshino, pid=25018) failed    TaskA()
Traceback (most recent call last):
  File "/Users/sh.hoshino/testdir/.venv/lib/python3.7/site-packages/luigi/worker.py", line 191, in run
    new_deps = self._run_get_new_deps()
  File "/Users/sh.hoshino/testdir/.venv/lib/python3.7/site-packages/luigi/worker.py", line 133, in _run_get_new_deps
    task_gen = self.task.run()
  File ",/excepthook_luigi.py", line 11, in run
    raise RuntimeError("Something")
RuntimeError: Something
DEBUG: 1 running tasks, waiting for next task to finish
INFO: Informed scheduler that task   TaskA__99914b932b   has status   FAILED
DEBUG: Asking scheduler for work...
DEBUG: Done
DEBUG: There are no more tasks to run at this time
INFO: Worker Worker(salt=070924467, workers=1, host=Mac-r0077, username=sh.hoshino, pid=25018) was stopped. Shutting down Keep-Alive thread
INFO: 
===== Luigi Execution Summary =====

Scheduled 1 tasks of which:
* 1 failed:
    - 1 TaskA()

This progress looks :( because there were failed tasks

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

Если я использую TaskA().run() вместо luigi.build , my_excepthook можно вызвать.
Есть ли какой-нибудь способ позвонить, кроме как с luigi.build помощью ?