Run finalizedBy when task is interrupted (ctrl-c)

So I don’t know if this is even possible in the JVM in general, to be honest, but figured I’d ask… Is it possible to run a finalizedBy if a subsequent operation has been interrupted with a ctrl-c? I think this would mean binding a task to a ‘System’'s shutdown hook. An example project would look something like

task prepare << {
    println "preparing"
}
  task longOperation << {
    sleep 50000
}
longOperation.dependsOn prepare
  task cleanup << {
    println "clean"
}
prepare.finalizedBy cleanup
cleanup.mustRunAfter longOperation

Ideally I’d want ‘cleanup’ to run regardless of the result of ‘longOperation’, but users can get impatient and ctrl-c the task and the entire gradle JVM shuts down (understandably) and then cleanup does not get run, a la:

$ ./gradlew -b /tmp/blah.gradle longOperation
Parallel execution is an incubating feature.
:prepare
preparing
> Building 33% > :longOperation^C
$