Skip to main content
. 2009 Mar 27;3:9. doi: 10.3389/neuro.11.009.2009

Figure 10.

Figure 10

A demonstration of code simplicity in Python: enabling threading. (A) This code example demonstrates how a function may be linked to a button press in a standard Python script using the thread running the main program. On the button click, the program asks the user to choose a file to load. The program then passes the file to the subroutine (Load_surface_file) and runs the subroutine. While the subroutine is running the user has to wait for the object to be loaded and returned to the main program before continuing. (B) This second code example shows that we can produce the same result using Python's threading module. First the threading module is imported. The functionality of code example in (A) is then added as a function (RunFunctionInThread). The button click in this instance calls a thread (my_thread.start) and runs the load routine will run in the background allowing the user to continue working while it is prepared. Note that threading only requires a few extra lines of simple code.