python多线程的用法之一

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:

上一篇:搭建高可用mongodb集群(一)——配置mongodb


下一篇:搭建高可用mongodb集群(二)—— 副本集