systemexit

Is there any way to get argparse.ArgumentParser.parse_args() not to exit on argument errors?

孤者浪人 提交于 2020-01-23 11:16:49
问题 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 it to raise a friendlier exception instead? I do not want to have to catch a SystemExit and extract the needed error message from it if there is any way around it. 回答1: You could use args, unknown = parser.parse_known_args(args_list) Then, any

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

拟墨画扇 提交于 2019-12-05 00:30:40
问题 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 I forgetting some setting somewhere? Below is the code that I'm using for the worker (worker.py): from celery import Celery from celery import signals app = Celery('tasks', set_as_current = True, broker='amqp://guest@localhost//', backend="mongodb

Raise unhandled exceptions in a thread in the main thread? [duplicate]

廉价感情. 提交于 2019-12-04 10:13:36
问题 This question already has answers here : Catch a thread's exception in the caller thread in Python (14 answers) Closed 12 months ago . 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 details with the stack trace, but bring down the whole process as well. I've considered that it might be

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

亡梦爱人 提交于 2019-12-03 14:16:07
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 I forgetting some setting somewhere? Below is the code that I'm using for the worker (worker.py): from celery import Celery from celery import signals app = Celery('tasks', set_as_current = True, broker='amqp://guest@localhost//', backend="mongodb://localhost//", ) app.config_from_object({ "CELERYD_MAX_TASKS_PER_CHILD": 1, "CELERYD_POOL": "solo",

Raise unhandled exceptions in a thread in the main thread? [duplicate]

二次信任 提交于 2019-12-03 06:12:32
This question already has answers here : Catch a thread's exception in the caller thread in Python (14 answers) 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 details with the stack trace, but bring down the whole process as well. I've considered that it might be possible to catch all exceptions in the threads, and reraise them on the main thread object, or perhaps it's possible to manually

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

我的未来我决定 提交于 2019-11-27 00:40:11
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 SystemExit and prevents the exit. This is normally great, but the specific situation I am trying to handle is one where our test framework has detected that it is configured to point to a non-test database. In this case I want to exit and prevent any further tests from being run. Of course since unittest traps the SystemExit and continues happily on it's way

Close application and remove from recent apps/

跟風遠走 提交于 2019-11-26 19:45:35
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 answered correctly. What I want: I want to show my app in recent apps list when it is running but when I close app then my process should be killed and application should be removed from recent apps list. Some answers I found: use System.exit(0); //doesn't clear app from recents OR use android.os.Process.killProcess(android.os.Process.myPid()); //doesn

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

蓝咒 提交于 2019-11-26 09:25:35
问题 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 SystemExit and prevents the exit. This is normally great, but the specific situation I am trying to handle is one where our test framework has detected that it is configured to point to a non-test database. In this case I want to exit and prevent any

Close application and remove from recent apps/

拈花ヽ惹草 提交于 2019-11-26 07:26:11
问题 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 answered correctly. What I want: I want to show my app in recent apps list when it is running but when I close app then my process should be killed and application should be removed from recent apps list. Some answers I found: use System.exit(0); /