I have got a python function that takes a few parameters and executes a few tasks (let's call it theFunc). While theFunc runs, internal variable resultingMessage is getting more and more lines, and I show it on GUI at the end of the execution. Ideally, I would like resultingMessage to be shown and updated on GUI as the execution of theFunc happens, not after it has finished, and to do it without polluting theFunc with GUI stuff (it is complicated enough already). What would be the best way to do it?
Two possible ways I could think of (both are quite far-fetch):

Have two threads: one executed theFunc and writes resultingMessage in a variable/file, the other checks this variable/file and updates GUI;
Instead of appending lines to resultingMessage, attach some "stream" to GUI element; adding lines to the "stream" would update GUI.

I guess there should be a conventional way to do it.
Environment: CPython 2.7, Win XP, WXPython
You would want to use threads. wxPython provides several thread-safe methods such as wx.CallAfter, wx.CallLater and wx.PostEvent. You can combine those with pubsub to send messages too! In your case, I think passing a wx method to wx.CallAfter with whatever text you wish to display would work just fine.
Updating GUI while execution a python function while keeping this function GUI-independent