赞
踩
import threading import time def td(): time.sleep(1) print('当前线程名字是:'+ threading.current_thread().name) time.sleep(1) if __name__ == '__main__': s_time = time.time() print('这是主线程:'+ threading.current_thread().name) tdg_list= [] for i in range(5): t = threading.Thread(target=td) tdg_list.append(t) for t in tdg_list: t.start() print('主线程结束了!' , threading.current_thread().name) print('一共用时:', time.time()-s_time)
import threading import time def td(): time.sleep(1) print('当前线程名字是:'+ threading.current_thread().name) time.sleep(1) if __name__ == '__main__': s_time = time.time() print('这是主线程:'+ threading.current_thread().name) tdg_list= [] for i in range(5): t = threading.Thread(target=td) tdg_list.append(t) for t in tdg_list: t.setDaemon(True) t.start() print('主线程结束了!' , threading.current_thread().name) print('一共用时:', time.time()-s_time)
import threading import time def td(): time.sleep(1) print('当前线程名字是:'+ threading.current_thread().name) time.sleep(1) if __name__ == '__main__': s_time = time.time() print('这是主线程:'+ threading.current_thread().name) tdg_list= [] for i in range(5): t = threading.Thread(target=td) tdg_list.append(t) for t in tdg_list: t.setDaemon(True) t.start() for i in tdg_list: t.join() print('主线程结束了!' , threading.current_thread().name) print('一共用时:', time.time()-s_time)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。