473,626 Members | 3,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Crashing Python.exe with TkInter


I've run into a problem with Python/TkInter crashing, with an
attempt to read illegal addresses, on Win on Win2000 and WinXP.

With some web-searching, I found that people say not to
manipulate TkInter from multiple threads, except that the call
event_generate( ) is safe. I assume the call adds an event to
Tk's queue, and later the thread running mainloop will() pick up
the event.

I tried to write a general-purpose thread-runner. In the code
below, 'thread-it' runs a given function in a new thread, saves
the result, and triggers event_generate( ). When the mainloop
handles the event, it calls a second given function with the
saved result.

The code below *seems* to work. It requires only the current
Python distribution. To make it usually crash, un-comment the
'print' statement in add_to_listbox( ). That's all.

With no prints, it works. Adding prints in various places
causes it usually to crash with an unreadable-memory error from
the OS. I get the same behavior on the command-line and in
Idle. Occasionally, it prints something like:

TclExecuteByteC ode: abnormal return at pc 45: stack top 39 < entry
stack top 59
TclExecuteByteC ode execution failure: end stack top < start stack top

which is usually also accompanied by the read addressing error.

I'm sure I've previously been able to print from multiple Python
threads. Can anyone tell what is going on?

from Tkinter import *
import thread
import time

class Application(Fra me):

def __init__(self):
Frame.__init__( self, None)
self.event_name _cntr = 0
self.pack()
self.listbox = Listbox(self)
self.listbox.pa ck(side=TOP)

def add_to_listbox( self, msg):
self.listbox.in sert(END, msg)
# print "Adding", msg

def thread_it(self, finish_func, asyc_func, args=()):
""" Create a thread that calls asyc_func(*args ), then trigger
an even with event_generate( ). When the event loop handles
the event, call finish_func with the return value of asyc_func.
"""
event_name = "<<j7A5x0VjqZ3b _%x>>" % self.event_name _cntr
self.event_name _cntr += 1
result = [None]
def _on_finish(_):
self.unbind(eve nt_name)
finish_func(res ult[0])
def do():
result[0] = asyc_func(*args )
self.event_gene rate(event_name )
self.bind(event _name, _on_finish)
thread.start_ne w_thread(do, ())

app = Application()

def fin(s):
""" When the async function returns, we'll add its output
to the list box.
"""
app.add_to_list box(s)

def async(n):
""" In the threads, we'll just sleep then return a string.
"""
time.sleep(2.0)
return "Got %d asyncronously." % n

for i in range(5):
# Run a few threads
app.thread_it(f in, async, [i])

app.mainloop()

Thanks,
--
--Bryan
Jul 18 '05 #1
0 1303

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3837
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or less - during my own installation of Python 2.3 on Fedora Core 1 Linux for a friend of mine). Anyway, HTH, L.
10
3681
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. Andrew dalke@dalkescientific.com
14
2723
by: Java and Swing | last post by:
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in= 0; char *aString = 0; char *bString = 0; MY_NUM *a;
1
2226
by: John Chambers | last post by:
Sp my latest adventure is attempting to use python's Tkinter module on a few machines. On my PB (OSX 10.3.9), I got the following confusing results: /Users/jc: python Python 2.3 (#1, Sep 13 2003, 00:49:11) on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import Tkinter Traceback (most recent call last): File "<stdin>", line 1, in ?
44
3687
by: jiang.haiyun | last post by:
Now i began to learn GUI programming. There are so many choices of GUI in the python world, wxPython, pyGTK, PyQT, Tkinter, .etc, it's difficult for a novice to decide, however. Can you draw a comparison among them on easy coding, pythonish design, beautiful and generous looking, powerful development toolkit, and sufficient documentation, .etc. It's helpful for a GUI beginner. Thank you.
40
2714
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I'm really annoyed at Python - and not for the reasons already mentioned on this list. Everyone know that programming is supposed to be a dark art, nearly impossible to learn. Computer code is supposed to be something impossible to read to the common person and yet reveal their secrets to the initiated - just remember the code displayed in the Matrix... Python takes all of that away. It is just too readable. Even beginners can...
13
3350
by: Daniel Fetchinson | last post by:
Was looking at PEP 3108, http://www.python.org/dev/peps/pep-3108/ , Is it just me or others also think that it would be a major loss to remove tkinter from the python core? PEP 3108 starts off with: Each module to be removed needs to have a justification as to why it should no longer be distributed with Python. then goes on with,
8
3274
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to my pc. But, it is not getting installed and is failing by throwing the below errors. Should i need to configure / install any specific files for resolving this issue ?
2
2160
by: Dudeja, Rajat | last post by:
Hi, So, now I've finally started using Eclipse and PyDev as an IDE for my GUI Application. I just wrote some sample programs as an hands on. Now I would like to take up Tkinter. I'm using Active State Python version 2.5 and found that there is not Tkinter and Tk module in it. To use Tkinter do I actually require Tk installed on my machine? Please suggest and where can I find both these modules?
0
8711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.