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

python多线程的用法之一

时间:2016-01-17 16:01:56      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

import threading
import time

class thread_1(threading.Thread):
sleep_time = 0
def __init__(self,id1):
self.id1 = id1
threading.Thread.__init__(self)


def run(self):
thread_1.sleep_time += 2
time.sleep(thread_1.sleep_time)
print(‘thread_num:‘,self.id1)
print(‘sleep_time %s:‘ %(thread_1.sleep_time))

class thread_2(threading.Thread):
sleep_time = 0
def __init__(self,id1):
self.id1 = id1
threading.Thread.__init__(self)
thread_2.sleep_time += 0.5
time.sleep(thread_2.sleep_time)

def run(self):
print(‘thread_num:‘,self.id1)
print(‘sleep_time %s:‘ %(thread_2.sleep_time))


t1 = thread_1(1)
t1.start()
t2 = thread_2(2)
t2.start()

----------------------------

thread_num: 2
sleep_time 0.5:
thread_num: 1
sleep_time 2:

python多线程的用法之一

标签:

原文地址:http://www.cnblogs.com/luyi5555/p/5137226.html

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