zoukankan      html  css  js  c++  java
  • multiprocssing,threading,多进程多线程初识

    1.  multiprocessing 多进程:

        import multiprocessing

        p = multiprocessing.Process(target = func,name = "自定义进程名",args = (),kwargs={})  生成一个子进程,args=(1,)里面传元组

        p.start()  启用进程

        

    2.  threading

        t = threading.Thread(target = func,args = (),kwargs={})  生成一个子线程

        t.start()    启用线程

        t.join()    主进程等待不往下执行,等子线程t完成后再往下执行

    图例:

        

     3.  threading.current_thread()     显示当前线程 

       multiprocessing.current_process()    显示当前进程

          

    4.  p.terminate()  中止子进程  线程不能中途终止

    5.  p.pid    进程的id

      

    6.  t.ident    线程的id

    7.  p.is_alive()  是否活着

       t.is_alive()

    8.  守护进程  p = multiprocessing.Process(target = func,daemon = True)  子进程在主进程代码执行完后就停止,线程也一样的操作

  • 相关阅读:
    基于Twisted的简单聊天室
    小学题的python实现
    初识Go(8)
    初识Go(7)
    初识Go(6)
    初识Go(5)
    初识Go(4)
    初识Go(3)
    初识Go(2)
    初识Go(1)
  • 原文地址:https://www.cnblogs.com/cxhzy/p/9982497.html
Copyright © 2011-2022 走看看