on nearly every platformthoughlong-running tasks like mail fetches and sends are spawned off as parallel threadsso that the gui remains active during the transfer--it continues updating itself and responding to new user requestswhile transfers occur in the background while that' true of threading in most guishere are two notes regarding pymailgui' specific implementation and threading modelgui updatesexit callback queue as we learned earlier in this bookonly the main thread that creates windows should generally update them see for more on thistkinter doesn' support parallel gui changes as resultpymailgui takes care to not do anything related to the user interface within threads that loadsendor delete email insteadthe main gui thread continues responding to user interface events and updatesand uses timer-based event to watch queue for exit callbacks to be added by worker threadsusing the thread tools we implemented earlier in (example - upon receiptthe main gui thread pulls the callback off the queue and invokes it to modify the gui in the main thread such queued exit callbacks can display fetched email messageupdate the mail index listchange progress indicatorreport an erroror close an email composition window--all are scheduled by worker threads on the queue but performed in the main gui thread this scheme makes the callback update actions automatically thread safesince they are run by one thread onlysuch gui updates cannot overlap in time to make this easypymailgui stores bound method objects on the thread queuewhich combine both the function to be called and the gui object itself since threads all run in the same process and memory spacethe gui object queued gives access to all gui state needed for exit updatesincluding displayed widget objects pymailgui also runs bound methods as thread actions to allow threads to update state in generaltoosubject to the next paragraph' rules other state updatesoperation overlap locks although the queued gui update callback scheme just described effectively restricts gui updates to the single main threadit' not enough to guarantee thread safety in general because some spawned threads update shared object state used by other threads ( mail caches)pymailgui also uses thread locks to prevent operations from overlapping in time if they could lead to state collisions this includes both operations that update shared objects in memory ( loading mail headers and content into caches)as well as operations that may update pop message numbers of loaded email ( deletionswhere thread overlap might be an issuethe gui tests the state of thread locksand pops up message when an operation is not currently allowed see the source code and this program' help text for specific cases where this rule is applied pymailgui demo