are you getting an error message?
# ask-marvin
n
are you getting an error message?
s
no, when i cancel, i dont have messages from on_cancel_fn()
n
• what version of prefect? • how are you attempting to cancel the flow run? ie UI or API or something else
s
prefect 3, i cancel in UI
šŸ‘ 1
for clarification i got only this: 114849.945 | INFO | prefect.workers.process.processworker f801058e-4b7f-43b4-87e8-854539e9ff3c - Found 1 flow runs awaiting cancellation. 114850.047 | INFO | prefect.flow_runs.worker - Cancelled flow run '785948b5-9082-4695-bc44-b123dd472f9e'! 114850.263 | ERROR | prefect.flow_runs.worker - Process 12936 exited with status code: 3
b
Hi Sergei! If you're using a Process worker, I believe you're running into a similar issue that this user reported in GitHub. The cancellation hook does seem to work reliably when using
.serve()
like so:
Copy code
from prefect import flow
from prefect.logging.loggers import flow_run_logger
import time

def log_something(flow, flow_run, state):
    flow_run_logger(flow_run, flow).info(f"Flow {flow.name} cancelled")

@flow(on_cancellation=[log_something])
def test_flow():
    time.sleep(30)
    return 42

if __name__=="__main__":
    test_flow.serve(name="my-cancelled-flow")
šŸ™Œ 1