Error Control C Exit 572 (0x23C): How to Fix it
To address this issue, you need to handle the error properly
When developing you may encounter the following code: ERROR_CONTROL_C_EXIT. Many users don’t know what this code represents, so let’s dive deeper and see what it does.
How can I fix ERROR_CONTROL_C_EXIT?
1. Modify the code
- Open your code.
- Next, use the following code
import signal
import sys
def handle_sigint(signum, frame):
print("\nCTRL+C detected. Performing cleanup...")
# Add any cleanup logic here
sys.exit(0) # Exit gracefully
signal.signal(signal.SIGINT, handle_sigint)
while True:
print("Running... Press CTRL+C to stop.")
- Save changes.
2. Log the interruption
- Open your code.
- Adjust it like this:
import signal
import sys
import logging
logging.basicConfig(filename='app.log', level=logging.INFO)
def handle_sigint(signum, frame):
logging.info("Application terminated by CTRL+C")
sys.exit(0)
signal.signal(signal.SIGINT, handle_sigint)
while True:
print("Running... Press CTRL+C to stop.")
- Save changes.
3. Use proper cleanup
- Open your code again.
- Modify it so it uses this logic:
import signal
import sys
file = open('example.txt', 'w')
def handle_sigint(signum, frame):
print("Closing file and exiting...")
file.close()
sys.exit(0)
signal.signal(signal.SIGINT, handle_sigint)
while True:
file.write("Writing data...\n")
- Save changes.
4. Additional tips
- Set a proper restart policy if the application terminates.
- Handle logging of unexpected exits.
- Inform users that this keyboard shortcut exits most command line applications.
In most cases, ERROR_CONTROL_C_EXIT doesn’t need additional handling, since it’s a regular occurrence when a user uses a keyboard shortcut to exit the code.
Keep in mind that this error sometimes comes with the following message: 572 (0x23C) {Application Exit by CTRL+C} The application terminated as a result of a CTRL+C.
This is just one of many issues you can encounter, and recently we wrote about Subprocess-exited-with-error and Kernel Stack Locked At Exit, so don’t miss them for more information.
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more
User forum
0 messages