Why does this code crash python?

Irmen de Jong irmen.NOSPAM at xs4all.nl
Sat Nov 11 14:28:41 EST 2006


Mythmon at gmail.com wrote:
> I am trying to make a program that will basically simulate a chess
> clock in python. To do this I have two threads running, one that
> updates the currently running clock, and one that watches for a
> keypress. I am using the effbot Console module, and that is where I get
> the events for the keypresses. But when I press space it crashes
> shortly after. The program stops, the Console closes, and windows says
> that the program pythonw.exe has had an unexpected reason to shut down.
> I am using python2.5.

Try not (re)using an object created in a certain thread in another thread.
You're creating a console object "c" and use it in both threads.

Try creating the console object for each thread by itself,
i.e. remove the global "c = Console.getconsole()" and replace
it by a getconsole() inside each thread class.

I don't have the Console module so I don't know if it fixes things
for you, but give it a try :)

--Irmen



More information about the Python-list mailing list