Skip to content

Commit a6dcfc5

Browse files
committed
fix: add SIGINT handler
Setup a SIGINT handler to gracefully exit the program once the user presses ctrl+c. Signed-off-by: Sébastien Han <seb@redhat.com>
1 parent e30aaa0 commit a6dcfc5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

torchchat.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import argparse
88
import logging
9-
import subprocess
9+
import signal
1010
import sys
1111

1212
# MPS ops missing with Multimodal torchtune
@@ -25,7 +25,15 @@
2525
default_device = "cpu"
2626

2727

28+
def signal_handler(sig, frame):
29+
print("\nInterrupted by user. Bye!\n")
30+
sys.exit(0)
31+
32+
2833
if __name__ == "__main__":
34+
# Set the signal handler for SIGINT
35+
signal.signal(signal.SIGINT, signal_handler)
36+
2937
# Initialize the top-level parser
3038
parser = argparse.ArgumentParser(
3139
prog="torchchat",

0 commit comments

Comments
 (0)