[Tkinter-discuss] tkinter and threading
glee at pharsight.com
Tue Jun 7 04:30:11 CEST 2005
Are Tkinter callbacks run in separate threads? Do I need to use threading locks to protect data shared between callbacks that can run at the same time? I'm running Python 2.3 and Tkinter on Windows.
I have two callbacks: cb_close and cb_run. cb_close cleans up, then uses Tkinter.Toplevel.destroy; it is bound to WM_DELETE_WINDOW via Tkinter.Toplevel.protocol.
cb_run uses a COM component to perform a lengthy operation. The COM component calls back to the Python world often enough that I can keep my GUI responsive using Tkinter.Toplevel.update.
Bad things happen if I allow cb_close to call destroy while cb_run is in progress: cb_run eventually asks the Tkinter world to post a completion dialog. To keep this from happening I use a state variable to tell cb_close that it should not call destroy if cb_run is in progress and to tell cb_run that it should not execute if a cb_close is in progress.
I can definitely get cb_close to run at the same time as cb_run, which suggests that the Tkinter eventloop executes its callbacks in separate threads. All this lead me to use a lock to protect read/write of the state variable. Was this necessary? Is there something in the way that Tkinter handles callbacks that automatically protects shared data structures?
Greg Lee / Pharsight Corporation / Suite 200
800 W El Camino / Mountain View CA 94040
voice: 650-314-3860 / fax: 650-314-3810
This email message (including any attachments)
is for the sole use of the intended recipient
and may contain confidential and proprietary
information. Any disclosure or distribution
to third parties that is not specifically
authorized by the sender is prohibited.
If you are not the intended recipient, please
contact the sender (greg at pharsight.com) by reply
email and destroy all copies of the original
message. Thank you.
More information about the Tkinter-discuss