Skip to content

Commit

Permalink
Added feature to interrupt y -N continuous commands. (Significant-Gra…
Browse files Browse the repository at this point in the history
…vitas#4230)

* Added feature to interrupt y -N continuous commands.

* Fixed formatting.

---------

Co-authored-by: Nicholas Tindle <[email protected]>
  • Loading branch information
2 people authored and ppetermann committed May 22, 2023
1 parent 34d933c commit d55e715
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import signal
import sys
from datetime import datetime

from colorama import Fore, Style
Expand Down Expand Up @@ -88,6 +90,20 @@ def start_interaction_loop(self):
arguments = None
user_input = ""

# Signal handler for interrupting y -N
def signal_handler(signum, frame):
if self.next_action_count == 0:
sys.exit()
else:
print(
Fore.RED
+ "Interrupt signal received. Stopping continuous command execution."
+ Style.RESET_ALL
)
self.next_action_count = 0

signal.signal(signal.SIGINT, signal_handler)

while True:
# Discontinue if continuous limit is reached
self.cycle_count += 1
Expand Down

0 comments on commit d55e715

Please sign in to comment.