Skip to content

Commit 0b385d3

Browse files
lesebJack-Khuu
andauthored
Setup a SIGINT handler to gracefully exit the program once the user presses ctrl+c (#1352)
Setup a SIGINT handler to gracefully exit the program once the user presses ctrl+c. Signed-off-by: Sébastien Han <[email protected]> Co-authored-by: Jack-Khuu <[email protected]>
1 parent fe257fd commit 0b385d3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: torchchat.py

+9-1
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)