码迷,mamicode.com
首页 > 编程语言 > 详细

python多进程

时间:2017-08-09 21:05:18      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:targe   变量   调度   对象   一个   python   组成   线程   reading   

1、多线程的理解

 线程是最小的执行单元,而进程由至少一个线程组成。线程的特点是线程之间可以共享内存和变量,资源消耗少。如何调度进程和线程,完全由操作系统决定,程序自己不能决定什么时候执行,执行多长时间。

2、Python多线程创建

 1 from threading import Thread
 2 import time
 3 # 1.如果多个线程执行的都是同一个函数的话,各自之间不会有影响,各是各的
 4 def test():
 5     time.sleep(1)
 6     print("----昨晚喝多了,下次少喝点---")
 7 
 8 for i in range(100):
 9     t = Thread(target=test) # 创建线程对象
10     t.start()  #执行线程

 

python多进程

标签:targe   变量   调度   对象   一个   python   组成   线程   reading   

原文地址:http://www.cnblogs.com/leon-coder/p/7327286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!