Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to see who can make Python have a fatal crash with the most creative code. This means that when the program runs, Windows for example, will take over and pop up with something like “IDLE has stopped working”, or Linux will do whatever Linux does when a program crashes.


  1. This must be made in Python 2.7 or above (So old bugs aren't exploited that have been fixed in future versions of Python).

  2. The definition of "crash" is "make IDLE or Python exit in an unintended way." This does not mean "make IDLE or Python halt and give a traceback". This also means exit, sys.quit, abort etc are not valid answers. For example, this will not be accepted:

    import sys
         print c # Crashes Here, as c is not defined.
     except NameError, SyntaxError:
         print "Oh No!"
  3. Making Python stop responding is not accepted.

  4. The code must be explained on what it does to crash. A link to a bug report is fine.

The most upvoted answer after 10 days wins! Begin!!

EDIT: May I make it clear that the objective is not to make Python just halt executing the program with a traceback. The objective is to make Python completely crash or stop working. This means that if this task is successfully accomplished, Windows would give this (I'm not crashing Word here, it's just an example of what should happen for a different program):

error dialogue

or this:

error dialogue 2

share|improve this question
The tag code-challenge requires an objective winning criterion. I think most creative isn't objective enough... – Howard Feb 27 '14 at 19:16
Ok - Ill change it to as short as possible, like most other challenges.. Creative is quite ambiguous actually... – George Feb 27 '14 at 19:17
@GeorgeH If creative is what you were looking for, popularity-contest works perfectly. I personally feel that this would be best as a popularity contest. In the future, you can run your question through the sandbox where these kinks can be worked out before posting. – Justin Feb 27 '14 at 20:04
And its a lot clearer this time too (Does this question have the most edits ever now!!) – George Feb 27 '14 at 21:58
@People with High Rep, my prnt in the question is intentional. – George Mar 1 '14 at 1:11

10 Answers 10

up vote 17 down vote accepted

Should have been a code-golfing contest ;) - I guess the creativity is the statement the code makes: "I just don't know what's happening here..."

Copy and paste the following character in IDLE running on Windows:


The crash has something to do with the character being encoded as UTF-16 by Windows and the unsuccessful conversion to a UTF-8 character by IDLE...

Edit: python bug #13153

share|improve this answer
I'm not sure if this is really a valid answer. The question says "when the program runs". But here the program is never really run. IDLE crashes when you merely paste the 𐒢, before you can even run it. – Sebastian Negraszus Feb 28 '14 at 17:08
Yeah, I have to agree with @Sebastian. In a Python program you start with a text file and run the Python interpreter on it, but it shouldn't matter how you make the text file. – David Z Mar 1 '14 at 6:11
Um... – Oberon Mar 1 '14 at 16:35
It works on Mac too! – TheDoctor Mar 4 '14 at 19:09

ctypes abuse:

import ctypes;ctypes.string_at(1)

This casts 1 to an address and dereferences it. On any sane system (i.e. one on which 0x00000001 is not a mapped address), this will segfault instantly.

share|improve this answer
On my machine, this doesn't seem to crash the interpreter. A traceback with a WindowsError error is displayed. – Dhara Feb 28 '14 at 8:14
@Dhara: Ah, that would be ctypes' structured exception handler catching the crash. I am certain you can crash Python with ctypes in Windows in some other way, but perhaps not in so few characters. – nneonneo Feb 28 '14 at 19:22


import sys
f=lambda f:f(f)

Not my own idea. Copied from the Python Wiki here.

This causes an infinite recursion, and is not stopped by the interpreter because we changed the recursion limit.

share|improve this answer
Thanks - this is a great answer, but for the wrong question! The objective has not been clarified in the question. Thanks for your answer though. – George Feb 27 '14 at 21:58
@George H Sorry I'm not using a Windows machine now, but isn't a segmentation fault that causes the python interpreter to dump core enough? – ace Feb 27 '14 at 22:20

signal abuse (non-Windows only):

import os;os.kill(0,4)

On most systems (on which SIGILL = 4) this will kill Python with an "illegal instruction" error.

Or you can kill the program using the killer alarm clock:

import signal;signal.alarm(1)

After one second, Python dies with the cryptic message "Alarm clock".

share|improve this answer
Other single character signal codes that work include 1, 3, 5, 6, 8 and 9. – ace Feb 27 '14 at 22:55

In Python 3.3:


In Python 2.7 code objects are slightly different:

exec type((lambda:0).func_code)(0,1,0,0,'Q',(),(),(),'','',0,'')

Yes, you can pass any old rubbish to the byte code interpreter and it executes it (Python issue #17187).

share|improve this answer
Shorter (Python 2.x): exec type((lambda:0).func_code)(0,1,0,0,'Q',(),(),(),'','',0,'') – nneonneo Feb 27 '14 at 22:52
Thanks! And in Python 3 we can use .__code__. – Gareth Rees Feb 27 '14 at 23:03

Recursive iterators use the C stack, not the Python stack (issue #14010 and issue #14507):

for _ in range(9**6):i=filter(int,i)
del i
share|improve this answer

One easy way to crash the interpreter is to trick it into deallocating None:

import ctypes, sys
(ctypes.c_char*4).from_address(id(None))[:] = '\0'*4

As a bonus, here's a clever way to segfault Python 2:

import ctypes, struct, sys
inner = ()
outer = (inner,)
c_outer = (ctypes.c_char * sys.getsizeof(outer)).from_address(id(outer))
inner_index = c_outer[:].find(struct.pack('P', id(inner)))
c_outer[inner_index:inner_index+struct.calcsize('P')] = struct.pack('P', id(outer))
print outer

What exactly this does is left as an exercise to the reader.

share|improve this answer
First one: set refcount of None to zero, causing it to be deallocated hilariously. Second one: construct and print a self-referencing tuple. – nneonneo Mar 3 '14 at 17:51

Someone thought they could prevent new FlagsType objects from being created by setting FlagsType.tp_new = NULL, but they forgot to remove the method (issue #13204):

import sys

(sys.version_info has the same bug.)

share|improve this answer

Use of alloca in ctypes module (issue #13096):

from ctypes import *
share|improve this answer

One possible way which crashes my Python with MemoryError:

share|improve this answer
This doesnt work for me - it just makes Python halt with a MemoryError. It needs to be closed by the OS. – George Feb 27 '14 at 19:24
Huh. The error happens at a surprisingly shallow depth. – user2357112 Feb 28 '14 at 13:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.