Python minimal thread (threading.Thread) example

This is a really simple example of how to add an extra thread to your Python script, to run some task in the background:

from threading import Thread
import time

def extra_thread_function():
    while True:
        print("extra_thread is running")

extra_thread = threading.Thread(target=extra_thread_function)

# TODO Your code for the main thread goes here!

# OPTIONAL: Wait for extra_thread to finish