Method for abruptly terminating a program. Skips cleanup performed on a standard exit call.
Questions tagged [systemexit]
45 questions
3
votes
1 answer
sys.exit in python gives a SystemExit error pystray
I am running a PYSTRAY icon which starts a console program. When I try stopping it with this code
def stop_rtd():
print("Stopping RTD")
sys.exit()
icon.stop()
The system throws back this error
An error occurred when calling message…

Tej
- 31
- 1
3
votes
3 answers
Python exceptions - catching all exceptions but the one expected
I am working on a simple automation script in Python, which could throw exceptions in various spots. In each of them I would like to log a specific message and exit the program. In order to do that, I raise SystemExit after catching the exception…

prkist
- 431
- 5
- 13
3
votes
1 answer
Is there any way to get argparse.ArgumentParser.parse_args() not to exit on argument errors?
For example:
import argparse
parser = arparse.ArgumentParser()
# parser.add_argument(...) ...
args = parser.parse_args(args_list)
The problem is, parser.parse_args automatically exits if there is an error in args_list. Is there a setting that gets…

Matt
- 21,026
- 18
- 63
- 115
2
votes
2 answers
SystemExit: `requests` library you installed has been been hijacked
I am trying to import libraries I have used previously to calculate metrics between text, one being evaluate package. When I import the package it says the requests package has been hijacked
I tried uninstalling python-requests, evaluate, and…

kraytdragon
- 41
- 3
2
votes
1 answer
In pytest, how to test for sys.exit('some error message')?
I'm a beginner to python and pytest. I have a function that I'm trying to test for the exceptions part with Pytest:
def read_data(args) -> tuple[Polyline, str]:
parsed_args = input_parsing_1(args)
try:
with open(parsed_args.f) as…

Maria Żukowska
- 51
- 6
2
votes
2 answers
How to exit from an endless Java program and print a message?
Say I have a java program (actually I wrote a CLI) which goes into an endless loop and within that loop it's incrementing a counter. When I hit Ctrl + C from my command line to exit from the program, can I print the value of the counter and then…

Saturnian
- 1,686
- 6
- 39
- 65
2
votes
2 answers
Python: handle sys.exit() in doctests
I am trying to use python doctests to test an error message that is being printed in a function. Below is my code
import sys
def get_values(vals=[]):
"""
Should split key:val and give values
>>> get_values(["abc"])
Error: could not…

allDoubts
- 67
- 8
1
vote
1 answer
I am getting 'SystemExit: 2' error , how to fix it
I am new to the machine learning coding . I am trying to run the code to find the number people in the video , image or by the live camera, but I am getting error
I am using Collab notebook to run it
'''
if __name__ == "__main__":
HOGCV =…

Sowmya reddy
- 11
- 1
- 3
1
vote
1 answer
How to assert logging error which is followed by a sys.exit()
I am using Python's logging module to generate an ERROR message in specific cases, followed by a sys.exit().
if platform is None:
logging.error(f'No platform provided!')
sys.exit()
Continue do other stuff
Now I am using pytest to unit…

laurentius
- 11
- 2
1
vote
2 answers
group_by ModuleNotFoundError: No module named 'dfply.group'; 'dfply' is not a package
I am working on Spyder (Anaconda). I always have several error messages since I work on Windows. I have already tried this code in Linux and It worked ! from dfply import * worked very well.
from dfply import *
from dfply.group import group_by…

CiaPy
- 25
- 6
1
vote
0 answers
Run args = parser.parse_args(). Error: SystemExit: 2
When learning a piece of python code, some problems have occurred .
code show as below:
parser = argparse.ArgumentParser()
parser.add_argument('--config_path', type=str, default="",
help='the location of the data…

MoMoMo
- 11
- 1
- 2
1
vote
0 answers
Python unit testing sys.exit call with assertRaises or mock.patch
I've read a lot of answers suggesting that the way to unit test sys.exit is to do the following:
with self.assertRaises(SystemExit) as system_exit:
function()
self.assertEqual(system_exit.exception_code, 1)
Does the above not actually raise a…

cubestack
- 11
- 1
1
vote
3 answers
Can I tell Python to ignore the rest of a file and/or exit without raising an exception as if the end of file was reached?
When I execute a Python script(*) and the end of the file is reached, I get back to the command prompt without any additional messages displayed. I would like to know whether there's a statement I can insert somewhere in the source file in order to…

Max
- 415
- 5
- 12
1
vote
1 answer
TensorFlow. When running fully_connected_feed.py, app.py occus a 'systemexit' error
I was just learning 'TensorFlow Mechanics 101'. Error occurred when I run fully_connected_feed.py for trainning the MNIST data:
Step 1800: loss = 0.30 (0.002 sec)
Step 1900: loss = 0.44 (0.003 sec)
Training Data Eval:
Num examples: 55000 Num…

Jason Wang
- 23
- 5
1
vote
3 answers
How to invoke shutdown hooks of a program running in another thread
I am writing automated tests for a Swing application using Jemmy framework.
My test suite run this application by invoking the main method of its Main class in a new thread.
I have already written a lot of GUI-related tests but now I have got a more…

livthomas
- 1,160
- 1
- 14
- 25