Skip to content

Commit 4f3d7dd

Browse files
committed
feat: add SIGTERM handler
1 parent fcdfbc8 commit 4f3d7dd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

protocol-serial-bridge.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import re
3+
import signal
34
import threading
45
import time
56

@@ -674,7 +675,15 @@ def start_cli(bridge: ProtocolSerialBridge):
674675
print("\nCLI thread interrupted.")
675676

676677

678+
def handle_sigterm(sig, frame):
679+
"""SIGTERM handler."""
680+
print("Received SIGTERM, exiting...")
681+
if bridge is ProtocolSerialBridge:
682+
bridge.close()
683+
684+
677685
if __name__ == "__main__":
686+
signal.signal(signal.SIGTERM, handle_sigterm)
678687
# Set up command line argument parsing
679688
parser = argparse.ArgumentParser(description="Linear Protocol Serial Bridge")
680689
parser.add_argument("--port", help="Serial port to send data (e.g., /dev/ttyUSB0)")

0 commit comments

Comments
 (0)