[Stackless] Tk and Stackless

Mike Fletcher mfletch at tpresence.com
Sat Oct 28 08:48:39 CEST 2000

Hi Seung,

I didn't respond to your question because I still haven't had any responses
from TK-knowledgable people regarding how to capture the "OnClose" event of
the root TK() widget in order to shut down the micro-thread running the TK
mainloop (you don't do that in your sample at all, incidentally).  The
attached code will run TK, it just doesn't properly exit when you close the
TK window (which means you need to manually kill the process after you close
the window (blargh)).

Here's the message sent to comp.lang.python:

Seems this didn't go through (or the subject wasn't clear enough).  I've
been asked how to run Tkinter under micro-threads.  I only use wxPython, so
I'm not really sure how to write the mainloop substitute for Tkinter.  For
wxPython I use the OnExit handler for the wxApp to kill the mainloop
micro-thread.  Could some Tkinter guru suggest the correct test/event for
when to shut down the mainloop?

Side note: are all the mouse interactions under Tkinter atomic C functions?
For instance, dragging or resizing the window stops all other micro-threads
until the drag/resize stops.

Any pointers appreciated,

8<_________________ Tkinter test ____________
import uthread9
from Tkinter import *
from _tkinter import dooneevent
def go():
	print 'starting TK'
	global root
	while 1: # should use some TK-specific mechanism for determining
when the root is closed, don't know what...
		if not dooneevent( tkinter.DONT_WAIT ):
			uthread9.wait( 0.01 )
	print 'somehow exited loop'

def yo( finishedThread ):
	for x in range(1000000):
		if x % 10000 == 0:
			print '.',
	print 'exited mainloop'

uthread9.new(yo, uthread9.new(go) )

8<______________ wxPython mainloop (from larger codebase) _______
	def MainLoop(self):
		# This outer loop determines when to exit the application,
		# this example we let the main frame reset this flag when it
		# closes.
		self.mainloopThread = uthread9.new( self.__mainLoop )
		uthread9.new( self.StartMUTech )
		if not uthread9.microThreadsRunning():
	def __mainLoop( self ):
			while 1:
				# This inner loop will process any GUI
events until there
				# are no more waiting.
				while self.Pending():
					uthread9.atomic( self.Dispatch )

				# Send idle events to idle handlers.  You
may want to throtle
				# this back a bit so there is not too much
CPU time spent in
				# the idle handlers.  For this example, I'll
just snooze a
				# little...
				uthread9.atomic( self.ProcessIdle )
				uthread9.wait( 0.01 ) # hack!
	def OnExit( self, event ):
		print 'closing mutech'
		print 'exiting'
		if self.mainloopThread:

 Mike C. Fletcher
 Designer, VR Plumber

-----Original Message-----
From: Seung Chan Lim [mailto:slim at maya.com]
Sent: Wednesday, October 25, 2000 11:33 AM
To: stackless at starship.python.net
Subject: [Stackless] Tk and Stackless

does the micro thread work with Tk()??
I ran a quick check, and it doesn't seem to work.

def go():

def yo():
    while 1:
        print i


in this case since yo is faster, it
keeps printing out the
numbers until it gets killed (by CTRL-C) and when it dies, go kicks in..

any help would be great,


Stackless mailing list
Stackless at starship.python.net

More information about the Stackless mailing list