code
from threading import Thread
from multiprocessing import Process
import os
 
 
def work(name):
    print('{} say hello'.format(name))
 
 
if __name__ == '__main__':
    # 在主进程下开启线程
    t=Thread(target=work,args=("thread",))
    t.start()
    print('主线程/主进程')
 
 
    # 在主进程下开启子进程
    t=Process(target=work,args=("progress",))
    t.start()
    print('主线程/主进程')
 
Outputs
macname@MacdeMacBook-Pro py % python3 cccccc.py
thread say hello
主线程/主进程
主线程/主进程
progress say hello
macname@MacdeMacBook-Pro py %

 

 
 
 

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2021-11-14
  • 2021-11-21
  • 2021-11-17
  • 2021-12-08
猜你喜欢
  • 2022-02-02
  • 2021-06-26
  • 2022-01-17
  • 2021-10-29
相关资源
相似解决方案