472,958 Members | 2,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 2980

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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.