【发布时间】:2015-01-10 18:45:08
【问题描述】:
这是我想如何使用线程的示例演示。
import threading
import time
def run():
print("started")
time.sleep(5)
print("ended")
thread = threading.Thread(target=run)
thread.start()
for i in range(4):
print("middle")
time.sleep(1)
我怎样才能使这个线程工作演示甚至来自多个文件?
例子:
# Main.py
import background
""" Here I will have a main program and \
I want the command from the background file to constantly run. \
Not just once at the start of the program """
第二个文件:
# background.py
while True:
print("This text should always be printing \
even when my code in the main function is running")
【问题讨论】:
标签: python-3.x python-multithreading