先看Code吧
import threading
import time
def process_1():
counter = 0
t = threading.currentThread()
while getattr(t, "loop_alive", True):
print('process_1counter:', counter)
counter += 1
time.sleep(1)
if counter > 80:
break
print('process_1 thread stop')
p1_thread = threading.Thread(target=p2, args=())
p1_thread.start()
time.sleep(10)
p1_thread.loop_alive = False