text scrolledtext(text pack(threadchecker(textstart thread loop in main thread text bind('' need list for maprange ok lambda eventlist(map(oneventrange( ))text mainloop(pop-up windowenter tk event loop this module' comments describe its implementationand its self-test code demonstrates how this interface is used notice how thread' behavior is split into main actionexit actionsand optional progress action--the main action runs in the new threadbut the others are queued to be dispatched in the main thread that isto use this moduleyou will essentially break modal operation into thread and post-thread stepswith an optional progress call generallyonly the thread step should be long running when example - is run standaloneon each button click in scrolledtestit starts up six threadsall running the threadaction function as this threaded function runscalls to the passed-in progress function place callback on the queuewhich invokes threadprogress in the main thread when the threaded function exitsthe interface layer will place callback on the queue that will invoke either threadexit or thread fail in the main threaddepending upon whether the threaded function raised an exception because all the callbacks placed on the queue are pulled off and run in the main thread' timer loopthis guarantees that gui updates occur in the main thread only and won' overlap in parallel figure - shows part of the output generated after clicking the example' window its exitfailureand progress messages are produced by callbacks added to the queue by spawned threads and invoked from the timer loop running in the main thread study this code for more details and try to trace through the self-test code this is bit complexand you may have to make more than one pass over this code to make sense of its juggling act once you get the hang of this paradigmthoughit provides general scheme for handling heterogeneous overlapping threads in uniform way pymailguifor examplewill do very much the same as onevent in the self-test code herewhenever it needs to start mail transfer passing bound method callbacks on queues technicallyto make this even more flexiblepymailgui in will queue bound methods with this module--callable objects thatas mentionedpair method function with an instance that gives access to state information and other methods in this modethe thread manager module' client code takes form that looks more like example - revision of the prior example' self-test using classes and methods gui coding techniques