Threading

Overview

Python supports threading in much the same way as many other languages do. Most threading functions are made available by adding the code import threading to the top of your Python script.

Gracefully Exiting Multiple Threads

I followed this example at regexprn.com for the most part, except I discovered the example code was buggy and had to make some tweaks, as outlined below.

 Note that the code in class MyThread1 can be copied to create as many threads as you want (for example, to create MyThread2).

Examples

The Columbus Radio project uses multiple Python threads for the UI control. The code is in the ColumbusRadio repo on GitHub. The threads should gracefully exit if Ctrl-C is pressed in the terminal while they are running.

Posted: January 3rd, 2015 at 9:43 am
Last Updated on: May 25th, 2017 at 10:25 am