Python threading minimal example

This minimal example shows how to create a thread that prints Hello world every second:

example.py
import threading
import time

def my_thread_func():
    while True:
        print("Hello world")
        time.sleep(1)

my_thread = threading.Thread(target=my_thread_func)
my_thread.start()

 


Check out similar posts by category: Python