473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Windows python/Pmw-tkinter problem



I'm having a problem on windows (both 2000 and XP) with a multi-threaded
tkinter gui application. The problem appears to be a deadlock condition
when a child thread pops up a
Pmw dialog window in the context of a main window. The problem does not
occur on HPUX or Linux. The following simple example code illustrates
the problem and the work around
I've come up with; However, I'd like, very much, to get rid of the kludgy
work around.

Running the following program without input options works (my work around)

WindowsProblem.py

Running the program with a '-r' option causes a deadlock condition and the
program hangs.

WindowsProblem.py -r

Anyone had a similar problem or know of a solution/patch for this problem?

Thanks,

-Bruce Davis

BTW I'm currently using Python 2.3.2 - the problem also occurs on Python
2.2. And, again, there is no need for the work around on HPUX or Linux. This
seems
to be a windows type of thing.


#!/usr/bin/env python

import thread, threading, Pmw, time, sys
from Tkinter import *
class mainWindow:

def __init__(self, root, winKludge):
self.root = root

# Create a simple frame with one button
fr = Frame(self.root)
button= Button(fr, text='Click to exit', command=self.NOP)
button.grid(row=0, column=0)
fr.grid(row=0, column=0)

# start a worker thread so as not to block the main window thread.
thread.start_new_thread(workerThread, (root, winKludge))

def NOP(self):
self.root.destroy()

def workerThread(parent, winKludge):
# sleep a while and pop up a dialog window.
time.sleep(2.0)
pu = popup(parent, winKludge)
pu.show()
class popup:

def __init__(self, root, winKludge):
self.root = root
self.winKludge = winKludge
if self.winKludge and sys.platform=='win32':
self.kludgeMutex = threading.Lock()
self.kludgeMutex.acquire()
self.condEvent = threading.Condition()
self.condEvent.acquire(1)
root.after_idle(self.windowsKludge)
self.condEvent.wait(30.0)
self.condEvent.release()
self.win = Pmw.MessageDialog(root,
separatorwidth=4,
message_text='Test',
buttons=('Click to exit',),
command=self.callBack,
)
self.win.withdraw()

def windowsKludge(self):
# need to block the main window thread to prevent the program hang
when creating the popup
self.condEvent.acquire(1)
self.condEvent.notify()
self.condEvent.release()
self.kludgeMutex.acquire()

def show(self):
if self.winKludge and sys.platform=='win32':
self.kludgeMutex.release()
self.root.after_idle(self.win.activate)
self.wait()
else:
self.win.activate(globalMode='nograb',
geometry='centerscreenalways')

def quitter(self):
if self.winKludge and sys.platform=='win32':
self.condEvent.acquire(1)
self.condEvent.notify()
self.condEvent.release()
self.win.deactivate()

def wait(self, timeOut=2000):
self.condEvent.acquire(1)
self.condEvent.wait(timeOut)
self.condEvent.release()

def callBack(self, result):
self.quitter()


if __name__ == '__main__':

usageStr="""

WindowsProblem [r] [h]
Simple program to demonstrate a problem that occurs on windows (2000 and
XP)
and a work around. The program works without the work around on HPUX and
Linux boxes.
Input options:
-h - displays this help message
-r - reproduce the problem

Without the -r option, there is no problem.
With the -r option, the window appears to deadlock and hang forever.

"""

import getopt
try:
optlist,args = getopt.getopt(sys.argv[1:],"hr")
except getopt.error,info:
Print (usageStr)
sys.exit(1)

winKludge = 1
for opt in optlist:
if opt[0] == '-h':
print usageStr
sys.exit(0)
elif opt[0] == '-r':
winKludge = 0

# Create the main window
root = Tk()
mainWindow(root, winKludge)
root.mainloop()
Jul 18 '05 #1
0 3023

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

Similar topics

2
by: Robin Becker | last post by:
I'm getting the following error when I attempt to run an app with Python 2.3. I suppose this was silently ignored under 2.2. With debugging I see that s==0 in _int = int ...... def atoi(s ,...
4
by: F. GEIGER | last post by:
Hi again, I'd like to rename a page of a notebook. Deleting the page and adding a new one is not really an option, because the page is filled with other controls already. So I looked into...
0
by: Karin Lagesen | last post by:
I have a gui with a graph area built with Pmw and Pmw.Blt. Through this gui I calculate some values that I would like to display in the graph area. Now, this worked fine when I made the graph in...
3
by: Mark Light | last post by:
Hi, I have a Pmw.Counter widget and I would like to add a command that is called on pressing either the up or down arrows (the command will be the same for both). I have managed to do this for the...
0
by: Wennie Hwang | last post by:
Hi, I am new to Python and I am trying to run an old program. I do not know what version this old program was running back in 2001 ( I know it was run successfully). I got the source codes from the...
1
by: giacomo boffi | last post by:
my question: is it possible to erase a graph, and reuse it? like in # x -> compute -> y g=Pmw.Blt.Graph(); g.pack() g.line_create(name,x,y) # other computing -> a better y # do something to...
9
by: StepH | last post by:
Hi, I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) distibution... I'v try to download btlz-for-8.3.exe, but when i try to install it, i've a msgbox saying to the file is...
1
by: Lyddall's | last post by:
Hello. I am new to this list, but wondered if anyone could help me. I have had Python set up with PMW and BLT on two machines previous to my current laptop, but I can't seem to get them all to...
217
by: gyromagnetic | last post by:
The following url points to an article written by Damian Conway entitled "Ten Essential Development Practices": http://www.perl.com/pub/a/2005/07/14/bestpractices.html Althought the article has...
5
by: deacon.sweeney | last post by:
Hi, I've been searching for a .resize()-like function to overload much like can be done for the delete window protocol as follows: toplevel.protocol("WM_DELETE_WINDOW", callback) I realize...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.