Questions tagged [systemexit]

Method for abruptly terminating a program. Skips cleanup performed on a standard exit call.

45 questions
77
votes
2 answers

Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught?

The docs say that calling sys.exit() raises a SystemExit exception which can be caught in outer levels. I have a situation in which I want to definitively and unquestionably exit from inside a test case, however the unittest module catches…
John
  • 14,944
  • 12
  • 57
  • 57
67
votes
6 answers

Close application and remove from recent apps/

I know this question is common and asked many times on Stack Overflow, but after visiting nearly the four pages of search engine results and nearly the 20 question of Stack Overflow regarding this issue, I found that none of them is resolved or…
Hamad
  • 5,096
  • 13
  • 37
  • 65
54
votes
1 answer

Unsupported @SuppressWarnings("PMD.DoNotCallSystemExit")

I need to use System.exit(0) in an application. Eclipse has the PMD plugin installed and complains about this line of code. Adding @SuppressWarnings ("PMD.DoNotCallSystemExit") remove that warning but now I get a warning that this SuppressWarnings…
user342495
  • 1,453
  • 1
  • 11
  • 10
16
votes
3 answers

Raise unhandled exceptions in a thread in the main thread?

There are some similar questions, but none supply the answer I require. If I create threads via threading.Thread, which then throw exceptions which are unhandled, those threads are terminated. I wish to retain the default print out of the exception…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
14
votes
6 answers

How to return a value and raise an Exception

I have two objectives with this try/except statement. It needs to return a value of 1 if no problems occurred, or 0 if any problems occurred. It needs to raise an exception and end the script. I have the return value working. I also have the…
misterbear
  • 803
  • 2
  • 13
  • 33
8
votes
2 answers

Using finishAndRemoveTask() method of Activity class on API levels lower than 21

I need to delete app from recently used apps list. There is no problem on API level 21 and above. I use finishAndRemoveTask() method. But that method cannot be used on API levels lover than 21. How can I call that method on API levels lover than…
cimenmus
  • 1,386
  • 4
  • 18
  • 31
8
votes
3 answers

What is the exact purpose of calling System.exit() in java

I am in a little bit confusion with system.exit. I founded some things about from this link. but I have some doubts in my mind. If I use system exit, what will happened to the created objects,variable and ect. Are everything get destroyed once I…
maXfenda
  • 214
  • 3
  • 10
7
votes
1 answer

python exit infinite while loop with KeyboardInterrupt exception

My while loop does not exit when Ctrl+C is pressed. It seemingly ignores my KeyboardInterrupt exception. The loop portion looks like this: while True: try: if subprocess_cnt <= max_subprocess: try: notifier.process_events() …
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
7
votes
2 answers

How to assert both UserWarning and SystemExit in pytest

Assert UserWarning and SystemExit in pytest In my application I have a function that when provided with wrong argument values will raise a UserWarnings from warnings module and then raises SystemExit from sys module. Code is something like: def…
everestial007
  • 6,665
  • 7
  • 32
  • 72
6
votes
3 answers

Is there a way to make py.test ignore SystemExit raised on a child process?

I'm testing a Python module which contains the following snippet of code. r, w = os.pipe() pid = os.fork() if pid: os.close(w) # use os.close() to close a file descriptor r = os.fdopen(r) #…
Richard Gomes
  • 5,675
  • 2
  • 44
  • 50
6
votes
1 answer

celery trying shutdown worker by raising SystemExit in task_postrun signal but always hangs and the main process never exits

I'm trying to shutdown the main celery process by raisin SystemExit() in the task_postrun signal. The signal gets fired just fine, and the exception gets raised, but the worker never completely exits and just hangs there. HOW DO I MAKE THIS WORK? Am…
Darryl Lickt
  • 183
  • 2
  • 9
5
votes
2 answers

Catch SystemExit message with Pytest

I am writing test using pytest. I have a case where some function throws SystemExit with some error message on terminal in case of wrong input. I want to write test for the case when SystemExit is thrown and verify that there is specific string in…
ParthS007
  • 2,581
  • 1
  • 22
  • 37
5
votes
2 answers

Can we use System.exit() in java Web Applications

We are developing the web application using java. I want to use System.exit() in one of my methods instead of return. As per my knowledge, the application will go into shut down mode if I use this. Could anybody give me suggestions on this?
User
  • 173
  • 1
  • 12
4
votes
1 answer

Is there a way to log stacktrace which called System.exit in Java

I think there is a way to do this with SecurityManager, but I don't want to introduce it in an App just for this. Is there a way to catch and log stacktrace of what called exit() using some other solution?
VextoR
  • 5,087
  • 22
  • 74
  • 109
4
votes
0 answers

Handle SystemExit with asyncio.gather correctly

I want to run asyncio.gather with some awaitables, which can raise SystemExit. import asyncio async def func(t): await asyncio.sleep(t) raise SystemExit('Err') async def main(): tasks = [asyncio.ensure_future(func(t)) for t in…
Alai
  • 123
  • 1
  • 8
1
2 3