python 进程
os.fork [知道即可]
自定义类继承进程
start() 调用run()
进程池pool
进程间通信queue
线程
死锁
银行家算法
生产消费模式
1.多线程 , start()方法是开启方法, join()目的是执行完才往下执行
#!/usr/bin/env python # -*- coding:utf-8 -*- import threading #线程 import time def music(num=5): #有一个参数 print("music start %s" %time.ctime()) time.sleep(num) print("music end %s" %time.ctime()) def game(num=3): #有一个参数 print("game start %s" %time.ctime()) time.sleep(num) print("game end %s" %time.ctime()) if __name__ == '__main__': t1=threading.Thread(target=music) t2=threading.Thread(target=game) t1.start() t2.start() t1.join() #t1执行完,才执行能执行下面的"ending....." t2.join() print("ending.........") #主线程输出ending ''' music start Thu Jul 13 14:30:25 2017 game start Thu Jul 13 14:30:25 2017 game end Thu Jul 13 14:30:28 2017 music end Thu Jul 13 14:30:30 2017 ending......... [Finished in 5.1s] '''
2.自定义线程, start()调用的是重写的 run()方法
#!/usr/bin/env python # -*- coding:utf-8 -*- import threading #线程 import time class MyThead(threading.Thread): def __init__(self,num): threading.Thread.__init__(self) self.num=num #start()会调用run()方法 def run(self): print "running on number:",self.num print "start time ",time.ctime() time.sleep(self.num) print "end time ",time.ctime() if __name__ == '__main__': t1=MyThead(3) t2=MyThead(4) t1.start() t2.start() print("ending.........") #主线程输出ending """ running on number: 3 start time Thu Jul 13 14:51:01 2017 running on number:ending......... 4 start time Thu Jul 13 14:51:01 2017 end time Thu Jul 13 14:51:04 2017 end time Thu Jul 13 14:51:05 2017 [Finished in 4.1s] """