When using any method of stoping a script, the program will just restart (python)

Description of the problem (please keep it simple and short):
when i try to use sys.exit(), exit() or quit(), only happens when using the run button not when using shell and doing python filename.py the only way to stop the program is keyboard interrupt (control C) and pressing the stop button
Explain what you were trying to do:
exit a program
What areas or features are involved?
console and python
Repl Cover Page Link/Screenshots/Etc: (to protect you and your code, never share your Repl join link outside of PMs)

Hey @gabrielzv1233!

Can you provide a link to your Repl so we can look into it further?

3 Likes

https://replit.com/@gabrielzv1233/A-python-problem-that-i-am-sending-to-replit?s=app

And also this is using the new format for python (the beta)

1 Like

@gabrielzv1233 does it work if you use a normal Python template? It could be caused from using the new template.

2 Likes

I tried this code in a stable version of Python (non-beta), and it works perfectly:


Maybe its a problem in the Beta version, which you are using currently in this repl @gabrielzv1233

3 Likes

This has also happened to me. Instead of quitting, Replit thinks the .replit file is broken. SS:


Maybe @ShaneAtReplit can help?

1 Like

Yes, I know that, this was just a bug report for the beta, instructed to email someone or put something on the Ask Replit site

3 Likes

TLDR: I’m pretty sure this is intended, and this isn’t a bug.

Replit doesn’t expect the Python process to end through exit(), and restarts the program to try again. The only reason it says “Giving up” is because the program is continuously being killed and Replit doesn’t know what is going on.

.replit’s [interpreter] section configures the Python process and REPL, so after the constant killing of the Python process, it thinks something within its configuration is likely malformed. Keep in mind Replit doesn’t know you are calling exit(), and IMO its best practice to let your code end naturally.

3 Likes

You can let it end naturally but it’s harder to do that, You have to tell every other operation that would happen next to not happen somehow, and just skip through all that It’s a major inconvenience to just let it naturally end and sometimes that’s just not possible

3 Likes

Yep, I totally agree. But, almost always your code could be refactored to allow it to end naturally, it’s usually a big hassle though, and that’s why exit() exists.

Maybe in the future though design your code in a way that it can end naturally though

3 Likes