|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 迷失山林 于 2016-1-24 11:33 编辑
import _thread as thread ,time
def counter(myId,count):
for i in range(count):
print('[%s]-->%s'%(myId,i))
for i in range(5):
thread.start_new_thread(counter,(i,5))
time.sleep(6)
print('exit')
如题。是不是跟电脑cpu有关系
这个多线程我也不是太清楚门道, 估计跟硬件有关?
我的输出是 - C:\Python34\python.exe E:/python/tmp.py
- [0]-->0
- [0]-->1
- [0]-->2
- [0]-->3
- [1]-->0
- [0]-->4
- [2]-->0
- [2]-->1
- [2]-->2
- [2]-->3
- [2]-->4
- [1]-->1
- [3]-->0
- [3]-->1
- [3]-->2
- [3]-->3
- [3]-->4
- [1]-->2
- [1]-->3
- [1]-->4
- [4]-->0
- [4]-->1
- [4]-->2
- [4]-->3
- [4]-->4
- exit
- Process finished with exit code 0
复制代码
|
|