Running code in the background with threads
All of the code we have written up to this point in the book can be described as single-threaded; that is, every statement is executed one at a time, the prior statement finishing before the next one is begun. Even asynchronous elements such as our Tkinter event queue, though they may change the order in which tasks are executed, still execute only one task at a time. This means that a long-running procedure like a slow network transaction or file read will unavoidably freeze up our application while it runs.
To see this in action, run the sample_rest_service.py
script included with the example code for Chapter 14 (make sure you run the Chapter 14 version, not the Chapter 13 version!). Now run ABQ Data Entry, make sure you've got some data in the database for today, and run the REST upload. The upload should take about 20 seconds, during which time the service script should be printing status messages like these:
File 0% uploaded...