Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow on_crashed hook does not run #16427

Open
julianhess opened this issue Dec 17, 2024 · 2 comments
Open

Flow on_crashed hook does not run #16427

julianhess opened this issue Dec 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@julianhess
Copy link

julianhess commented Dec 17, 2024

Bug summary

The on_crashed hook does not execute, even though Prefect is clearly transitioning to a Crashed state. For instance, when a flow is sent a SIGINT via ^C, Prefect correctly traps the interrupt signal and transitions to a Crashed state but then does not execute the hook:

import prefect
from time import sleep

def crash_hook(*args):
    print("crashed!!!")

@prefect.flow(name = "test", on_crashed = [crash_hook])
def flow():
    sleep(10)

>>> flow()
21:07:07.610 | INFO    | prefect.engine - Created flow run 'spiritual-llama' for flow 'test'
21:07:07.612 | INFO    | prefect.engine - View at http://127.0.0.1:4200/runs/flow-run/2d5a7b50-5eb5-4f80-a98b-867b84908c4c
^C21:07:11.196 | ERROR   | Flow run 'spiritual-llama' - Crash detected! Execution was aborted by an interrupt signal.
21:07:11.235 | ERROR   | Flow run 'spiritual-llama' - Finished in state Crashed('Execution was aborted by an interrupt signal.')
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
...
<standard stack trace>
...

As you can see, crash_hook does not execute at all.

Note that the hook also fails to execute for other sorts of crash (not just SIGINT), e.g.

@prefect.flow(name = "test", on_crashed = [crash_hook])
def flow():
    raise SystemExit("crash!")

>>> flow()
21:18:39.626 | INFO    | prefect.engine - Created flow run 'amigurumi-chinchilla' for flow 'test'
21:18:39.627 | INFO    | prefect.engine - View at http://127.0.0.1:4200/runs/flow-run/73be1fc7-344b-4293-abe2-86c20c62e815
21:18:39.671 | ERROR   | Flow run 'amigurumi-chinchilla' - Crash detected! Execution was aborted by Python system exit call.
21:18:39.697 | ERROR   | Flow run 'amigurumi-chinchilla' - Finished in state Crashed('Execution was aborted by Python system exit call.')
An exception has occurred, use %tb to see the full traceback.

SystemExit: crash!

Again, the crash is properly intercepted, but the hook does not fire.

Version info

Version:             3.1.5
API version:         0.8.4
Python version:      3.12.7
Git commit:          3c06654e
Built:               Mon, Dec 2, 2024 6:57 PM
OS/Arch:             linux/x86_64
Profile:             local
Server type:         server
Pydantic version:    2.10.3

Additional context

No response

@julianhess julianhess added the bug Something isn't working label Dec 17, 2024
@zzstoatzz
Copy link
Collaborator

thank you for the report and the MRE @julianhess - we'll take a look at this!

@williamjamir
Copy link
Contributor

@zzstoatzz Perhaps this task at #16436 can help clarify the issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants