Python: Minimalbeispiel threading.Thread

English Deutsch

Dieses Beispiel zeigt, wie man threading.Thread ableitet und startet:

thread_example.py
#!/usr/bin/env python3
import threading

class MyThread(threading.Thread):
    def run(self):
        print("Mein Thread!")

my_thread = MyThread()
my_thread.start()
print("Haupt-Thread")

Dies gibt aus

thread_output.txt
Mein Thread!
Haupt-Thread

(es könnte auch Haupt-Thread zuerst ausgeben, je nachdem, was zuerst ausgeführt wird)


Check out similar posts by category: Python