# automation-api


03/02/2022, 9:09 PM
Hello, does anyone know the best way to handle a graceful stop/cancel of a running pulumi automation command in Python? I started down the path of spawning a thread which then runs the pulumi command and the main will handle a sigterm or keyboard interrupt. That seems to work for any part of the process except when a pulumi command is running (up, refresh, etc.). If a KeyboardInterrupt or sigterm happens when the pulumi command is running my thread stop workflow does start but unfortunately the pulumi cmd just throws a CommandError exception with the code of -2 which makes me think it is also canceling on the keyboard interrupt on it’s own but not gracefully stopping.