[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,
Mike

8<_________________ Tkinter test ____________
import uthread9
from Tkinter import *
from _tkinter import dooneevent
def go():
	print 'starting TK'
	global root
	root=Tk()
	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 ):
	i=0
	for x in range(1000000):
		if x % 10000 == 0:
			print '.',
	finishedThread.exit()
	print 'exited mainloop'

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

8<______________ wxPython mainloop (from larger codebase) _______
	def MainLoop(self):
		# This outer loop determines when to exit the application,
for
		# 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():
			uthread9.run()
	def __mainLoop( self ):
		try:
			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.switchContext()
				uthread9.atomic( self.ProcessIdle )
				uthread9.wait( 0.01 ) # hack!
		except:
			traceback.print_exc()
	def OnExit( self, event ):
		print 'closing mutech'
		self.MUTech.close()
		print 'exiting'
		event.Skip()
		if self.mainloopThread:
			self.mainloopThread.exit()



__________________________________
 Mike C. Fletcher
 Designer, VR Plumber
 http://members.home.com/mcfletch



-----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():
    root=Tk()

def yo():
    i=0
    while 1:
        i=i+1
        print i

uthread9.new(yo)
uthread9.new(go)
uthread9.run()

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,

thanks,

slim
_______________________________________________
Stackless mailing list
Stackless at starship.python.net
http://starship.python.net/mailman/listinfo/stackless



More information about the Stackless mailing list