python多线程
来源:互联网 发布:python编写上位机 编辑:程序博客网 时间:2024/05/22 14:48
#-*- coding:utf-8 -*-import threadingfrom time import ctime#先定义两个函数def add(n): sum=0 for i in range(0,n): sum=sum+i print 'add:%s\n'%sumdef mut(p): sum=1 for j in range(1,p): sum=sum*j print 'mut:%s\n'%sum#创建线程,先将两个函数存入threads中,再遍历调用threads=[]t1=threading.Thread(target=add(101))threads.append(t1)t2=threading.Thread(target=mut(20))threads.append(t2)if __name__=='__main__': for t in threads: # setDaemon(True)将线程声明为守护线程,必须在start() 方法调用之前设置 # ,如果不设置为守护线程程序会被无限挂起。子线程启动后,父线程也继续执行下去, # 当父线程执行完最后一条语句print "all over %s" %ctime()后,没有等待子线程, # 直接就退出了,同时子线程也一同结束。 t.setDaemon(True) t.start() print 'all over %s'%ctime()
阅读全文
0 0
- Python多线程
- Python多线程
- Python多线程
- python多线程
- python 多线程
- python多线程
- python多线程
- python 多线程
- python多线程
- Python多线程
- Python 多线程
- python多线程
- python 多线程
- {python多线程}
- Python 多线程
- Python多线程
- python 多线程
- Python 多线程
- 【04】vue.js — 百度搜索数据案例
- 第二课 Python爬虫网络请求request模块详解
- Eclipse背景颜色修改
- 中文翻译The Django Book
- spring cloud config整合gitlab搭建分布式的配置中心
- python多线程
- Palindrome Number
- 爬虫进程
- Python下如何使用CGI
- Kubernetes主机和容器的监控方案
- elasticsearch 类型中添加新的字段
- Vue2.0 -- Eslint 规则说明
- 学习JMeter的笔记
- Tree Traversals Again