父线程,没有等子线程执行完就退出
来源:互联网 发布:淘宝售假降权多久恢复 编辑:程序博客网 时间:2024/06/01 08:27
# -*- coding: utf-8 -*-import threadingfrom time import ctime,sleepdef music(func): for i in range(3): print "I was listening to %s. %s" %(func,ctime()) sleep(2)def move(func): for i in range(5): print "I was at the %s! %s" %(func,ctime()) sleep(5)threads = []t1 = threading.Thread(target=music,args=(u'爱情买卖',))threads.append(t1)t2 = threading.Thread(target=move,args=(u'阿凡达',))threads.append(t2)if __name__ == '__main__': for t in threads: #t.setDaemon(True) t.start() t.join() print "all over %s" %ctime()C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a4.pyI was listening to 爱情买卖. Sat Oct 14 13:15:54 2017I was at the 阿凡达! Sat Oct 14 13:15:54 2017I was listening to 爱情买卖. Sat Oct 14 13:15:56 2017I was listening to 爱情买卖. Sat Oct 14 13:15:58 2017I was at the 阿凡达! Sat Oct 14 13:15:59 2017I was at the 阿凡达! Sat Oct 14 13:16:04 2017I was at the 阿凡达! Sat Oct 14 13:16:09 2017I was at the 阿凡达! Sat Oct 14 13:16:14 2017all over Sat Oct 14 13:16:19 2017Process finished with exit code 0此时是并行执行,执行的时间是25S# -*- coding: utf-8 -*-import threadingfrom time import ctime,sleepdef music(func): for i in range(3): print "I was listening to %s. %s" %(func,ctime()) sleep(2)def move(func): for i in range(5): print "I was at the %s! %s" %(func,ctime()) sleep(5)threads = []t1 = threading.Thread(target=music,args=(u'爱情买卖',))threads.append(t1)t2 = threading.Thread(target=move,args=(u'阿凡达',))threads.append(t2)if __name__ == '__main__': for t in threads: #t.setDaemon(True) t.start() t.join() print "all over %s" %ctime()C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a4.pyI was listening to 爱情买卖. Sat Oct 14 13:17:10 2017I was listening to 爱情买卖. Sat Oct 14 13:17:12 2017I was listening to 爱情买卖. Sat Oct 14 13:17:14 2017I was at the 阿凡达! Sat Oct 14 13:17:16 2017I was at the 阿凡达! Sat Oct 14 13:17:21 2017I was at the 阿凡达! Sat Oct 14 13:17:26 2017I was at the 阿凡达! Sat Oct 14 13:17:31 2017I was at the 阿凡达! Sat Oct 14 13:17:36 2017all over Sat Oct 14 13:17:41 2017Process finished with exit code 0此时是串行,花了31S# -*- coding: utf-8 -*-import threadingfrom time import ctime,sleepdef music(func): for i in range(3): print "I was listening to %s. %s" %(func,ctime()) sleep(2)def move(func): for i in range(5): print "I was at the %s! %s" %(func,ctime()) sleep(5)threads = []t1 = threading.Thread(target=music,args=(u'爱情买卖',))threads.append(t1)t2 = threading.Thread(target=move,args=(u'阿凡达',))threads.append(t2)if __name__ == '__main__': for t in threads: t.setDaemon(True) t.start() #t.join() print "all over %s" %ctime()C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a4.pyI was listening to 爱情买卖. Sat Oct 14 13:21:49 2017I was at the 阿凡达! Sat Oct 14 13:21:49 2017 all over Sat Oct 14 13:21:49 2017Process finished with exit code 0此时父线程,没有等子线程执行完就退出了
阅读全文
0 0
- 父线程,没有等子线程执行完就退出
- 等子线程Thread执行完之后再执行mian线程的UI更新等等
- java多线程 主线程等子线程执行完毕
- GCD退出线程执行
- 这个主要是由于tomcat应用服务中有非daemon线程没有关闭。而根据jvm退出规则,只要有非daemon线程存在,jvm就不会退出 。
- 关于线程的执行和退出
- 关于线程的执行和退出
- 孤儿进程和僵尸进程 父进程没有执行wait就退出了
- 退出线程
- 退出线程
- 退出线程
- 线程退出
- java线程--线程退出
- Handler退出,线程退出
- 父线程退出后, 子线程是否会退出
- 【Win32多线程】创建线程、获取线程执行状态、退出线程、错误处理
- ios 保留子线程不退出可以继续执行任务
- 线程【六】线程安全退出
- 关于使用PyTorch设置多线程(threads)进行数据读取而导致GPU显存始终不释放的问题
- 原生 js 计算时间差
- 【Shiro权限管理】2.Shiro的HelloWorld程序
- CentOS 设置mysql的远程访问
- 【c基础】c语言精髓知识点总结
- 父线程,没有等子线程执行完就退出
- 区块链技术学习(1 ):搭建以太坊私链
- js 将一大段时间均分为很多个小时间段
- ThinkPHP 3.2.3 使用 PHPExcel 处理 Excel 表格
- 编辑距离C++实现(poj3356)
- PTA 数据结构 6-1 循环单链表区间删除
- Linux之shell脚本
- failed to execute prompt script (exit code 1)
- Qt入门-文件读写