C uses abort
to terminate the process by raising a SIGABRT signal. What is the equivalent abort
in Python? Thanks.
Asked
Active
Viewed 9,286 times
3

wad
- 2,491
- 3
- 14
- 16
-
1I guess you could send a SIGABRT signal to the parent process? Why do you need this? – Martijn Pieters Apr 09 '17 at 12:25
-
Are you looking for [this](http://stackoverflow.com/questions/179369/how-do-i-abort-the-execution-of-a-python-script)? – gsamaras Apr 09 '17 at 12:26
-
I suspect however that just `sys.exit()` suffices for your needs. – Martijn Pieters Apr 09 '17 at 12:26
-
No point tagging C, since the question isn't *about* C. Removed tag – StoryTeller - Unslander Monica Apr 09 '17 at 12:26
-
Think in Python and your life will be easier. – Billal Begueradj Apr 09 '17 at 12:30
1 Answers
0
Try this:
import sys
sys.exit()
You can also give some text as a parameter to print the error message.
sys.exit("This is the error")

Arvindsinc2
- 716
- 7
- 18
-
So, sys.exit is going to terminate the process, rather than shut down the whole python program, right? – wad Apr 09 '17 at 12:29
-
-
Since exit() only raises an exception, it will only exit the process when called from the main thread, and the exception is not intercepted. – Arvindsinc2 Apr 09 '17 at 12:33
-
1No, this is normal exit. `os.abort()` calls C `abort`. Why is this question marked as duplicate when the linked questions do not aswer? – vaclav.blazek May 21 '19 at 13:01