Skip to content

Commit

Permalink
handling KeyboardInterrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
bazkiaei committed Aug 6, 2023
1 parent 48c9544 commit 0d75e3c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions scripts/sync_data_with_remote_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,16 @@ def transfer_data(self, filename, destination):
)
archiver.start()

while True:
if not archiver.is_running:
raise error.PanError("Archiver is no longer running.")
time.sleep(10)
try:
while True:
if not archiver.is_running:
raise error.PanError("Archiver is no longer running.")
time.sleep(10)
except (KeyboardInterrupt, SystemExit):
# Gracefully handle KeyboardInterrupt (Ctrl+C) and SystemExit during file transfer
archiver.logger.info("KeyboardInterrupt received. Stopping the RemoteArchiver gracefully...")
archiver.stop()

archiver.logger.info("Archiver stopped.")
# Make sure to exit the script properly after handling the KeyboardInterrupt or SystemExit
sys.exit(0)

0 comments on commit 0d75e3c

Please sign in to comment.