• 多进程


    code
    import os
    from multiprocessing import Process
     
     
    def f(x):
        print('子进程id :',os.getpid(),'父进程id :',os.getppid())
        return x*x
     
     
    if __name__ == '__main__':
        print('主进程id :', os.getpid())
        p_lst = []
        for i in range(5):
            p = Process(target=f, args=(i,))
            p.start()
    Outputs
    macname@MacdeMacBook-Pro py % python3 cccccc.py
    主进程id : 57001
    子进程id : 57002 父进程id : 57001
    子进程id : 57003 父进程id : 57001
    子进程id : 57004 父进程id : 57001
    子进程id : 57005 父进程id : 57001
    子进程id : 57006 父进程id : 57001
    macname@MacdeMacBook-Pro py %
     
     
    Code
    import time
    from multiprocessing import Process
     
    def f(name):
        print('hello', name)
        time.sleep(1)
     
    if __name__ == '__main__':
        p_lst = []
        for i in range(5):
            p = Process(target=f, args=('bob',))
            p.start()
            p_lst.append(p)
    Outputs
    macname@MacdeMacBook-Pro py % python3 cccccc.py
    hello bob
    hello bob
    hello bob
    hello bob
    hello bob
    macname@MacdeMacBook-Pro py %
     
     
     
     
     
     
     
     
     
     
     
     
     
     

  • 相关阅读:
    Go语言从入门到放弃(三) 布尔/数字/格式化输出
    11. GLOBAL_VARIABLES 与 SESSION_VARIABLES
    10. GLOBAL_STATUS 与 SESSION_STATUS
    9. FILES
    8. EVENTS
    7. ENGINES
    6. COLUMN_PRIVILEGES
    5. COLUMNS
    4. COLLATION_CHARACTER_SET_APPLICABILITY
    3. COLLATIONS
  • 原文地址:https://www.cnblogs.com/sea-stream/p/14193099.html
Copyright © 2020-2023  润新知