time sleep( if progressprogress(iif id = raise exception access to object state here progress callbackqueued odd numberedfail thread callbacksdispatched off queue in main thread def threadexit(selfmyname)self text insert('end''% \texit\nmynameself text see('end'def threadfail(selfexc_infomyname)have access to self state self text insert('end''% \tfail\ % \ (mynameexc_info[ ])self text see('end'def threadprogress(selfcountmyname)self text insert('end''% \tprog\ % \ (mynamecount)self text see('end'self text update(works hererun in main thread if __name__ ='__main__'mygui(text mainloop(this code both queues bound methods as thread exit and progress actions and runs bound methods as the thread' main action itself as we learned in because threads all run in the same process and memory spacebound methods reference the original in-process instance objectnot copy of it this allows them to update the gui and other implementation state directly furthermorebecause bound methods are normal objects which pass for callables interchangeably with simple functionsusing them both on queues and in threads this way just works to manythis broadly shared state of threads is one of their primary advantages over processes watch for the more realistic application of this module in ' pymailguiwhere it will serve as the core thread exit and progress dispatch engine therewe'll also run bound methods as thread actionstooallowing both threads and their queued actions to access shared mutable object state of the gui as we'll seequeued action updates are automatically made thread-safe by this module' protocolbecause they run in the main thread only other state updates to shared objects performed in spawned threadsthoughmay still have to be synchronized separately if they might overlap with other threadsand are made outside the scope of the callback queue direct update to mail cachefor instancemight lock out other operations until finished more ways to add guis to non-gui code sometimesguis pop up quite unexpectedly perhaps you haven' learned gui programming yetor perhaps you're just pining for non-event-driven days past but for whatever reasonyou may have written program to interact with user in an interactive consoleonly to decide later that interaction in real gui would be much nicer what to do gui coding techniques