zoukankan      html  css  js  c++  java
  • 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]
    """
    

      

  • 相关阅读:
    一种高压侧母线过流检测电路的实现
    编程逻辑之状态机学习
    STM32——驱动DS18B20
    迪文屏所有控件测试
    EC11使用原理简介以及LL库源码
    FreeRTOS API使用栗子
    常用官网链接
    CubeMX之FreeRTOS学习day02
    跟工程师学嵌入式开发:基于STM32和μC OS-Ⅲ(学习笔记)
    CubeMX之FreeRTOS学习day01
  • 原文地址:https://www.cnblogs.com/alamZ/p/7153638.html
Copyright © 2011-2022 走看看