I'm creating an application with python 2.7 and wxpython 2.8 that should execute a long loop (some hours) on a list of files. 
I programmed a button that should interrupt the loop as I press it, but at the moment I start the application, it freezes and I can't interact in any way until the loop ends.
I also tried to add a small period of sleep with time.sleep, up to 1 second, which is really bad for the speed and doesn't resolve the issue.
Is there a way to run this loop "in the background", so that the user can still modify some parameters and more important stop the loop?
I can say about the loop that it doesn't require a lot of resources, it just requires a lot of time, so I don't understand why it freezes.
Thanks in advance for the help!
Using threads in the standard solution for this type of problem.  The wxPython demo under Processes and Events | Threads has a working example of using threads.
There are a few issues when running threads from wxPython (and most other guis), so you might want to read the comments in the example, and maybe the wiki to understand what's going on, etc. In particular, wxPython needs to be run from the main thread, so do your file processing in a different thread, and then your file processing should communicate with the main thread using something like wx.PostEvent or wx.CallAfter.
wxPython app frozen during the execution