Micro-threads: Tkinter mainloop substitutes...

Mike Fletcher mfletch at tpresence.com
Tue Oct 24 00:38:41 EDT 2000


Got a request for how to use Tkinter with micro-threads.  I only use
wxPython, so I'm unsure what check to make to see if the mainloop-substitute
can exit (can't use the default one 'cause it's apparently a C loop that
doesn't release the interpreter lock (at least, that's the way it looks to
me).  Any Tkinter gurus able to supply the correct check (see the while
line)?

Thanks all,
Mike

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...
		dooneevent( tkinter.DONT_WAIT )
		uthread9.wait( 0.01 ) # hacky, maybe check to see if any
events were processed, then decide whether to wait.
	print 'somehow exited loop'

def yo():
	i=0
	for x in range(1000):
		try:
			print '.',
		except:
			pass

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





More information about the Python-list mailing list