Python threading.Thread 最小示例
此示例展示如何子类化并启动 threading.Thread:
thread_example.py
#!/usr/bin/env python3
import threading
class MyThread(threading.Thread):
def run(self):
print("My thread!")
my_thread = MyThread()
my_thread.start()
print("Main thread")这将打印
thread_output.txt
My thread!
Main thread(它也可能先打印 Main thread,取决于哪个先执行)
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow