Allow for graceful termination of the program started by sbt run
See original GitHub issueEnabling cancelable in Global := true
allows to press Ctrl+C and terminate the running program without terminating SBT, however the way how it is handled is quite surprising and doesn’t really do what is typically expected from Ctrl+C.
Ctrl+C sends the TERM signal to the application, not KILL. Unfortunately SBT behaves as if it was requested a KILL and interrupts the application. In forked mode, it also seems to kill the JVM very quickly after the application receives the TERM signal. This gives no way for the application to terminate gracefully as it would do when running without SBT supervision.
Hitting Ctrl+C inside of sbt run should pass the TERM signal to the running application and just let the application decide how it handles it. Most of applications know what to do. Maybe, if some users still insist on hard terminating of the process (if it was frozen or doesn’t respond to normal TERM), the second Ctrl+C would invoke the current behaviour and interrupt / kill the application.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:12
- Comments:10 (2 by maintainers)
I just put
fork in Global := true
to my build.sbt and now it works as expected. I can Ctrl+C my running process and it lets my code handle it. I also havecancelable in Global := true
This can’t really be done in a platform independent way for the forked jvm. For in process
run
we can interrupt the main thread and the application will have an opportunity to recover and clean up after itself.