"for/while ... break(by any means) ... else" make sense?

Chris Angelico rosuav at gmail.com
Thu Jun 30 00:40:20 EDT 2016


On Thu, Jun 30, 2016 at 2:12 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, 30 Jun 2016 11:28 am, Chris Angelico wrote:
>
>> On Thu, Jun 30, 2016 at 10:27 AM, Steven D'Aprano <steve at pearwood.info>
>> wrote:
>>> Following os.abort(), the interpreter exits in the hardest, quickest
>>> manner possible.
>>
>> os.kill(os.getpid(), 9)
>>
>> Now THAT is the hardest way to abort. You ain't comin' back from this one!
>
> The docs say it will abort in the hardest way possible, by dumping core or
> equivalent. I *think* I recall seeing os.abort() actually segfault at some
> point, but I can't replicate that now.
>
> I tried to find the actual implementation of os.abort(), but I couldn't work
> out where it was or what it does. Can somebody enlighten me?

My expectation is that it'd be something like this:

def abort():
     if sys.platform == 'windows':
          some_win32_api_call()
     signal.signal(signal.SIGABRT, signal.SIG_DFL)
     kill(getpid(), signal.SIGABRT)

Certainly, after a call to os.abort() under Linux, the process is
recorded as having terminated with signal 6 (SIGABRT), and the
intended purpose of that signal is "abort the process abnormally,
possibly dumping core".

ChrisA



More information about the Python-list mailing list