1. 程式人生 > >Python 進程

Python 進程

target print .get __main__ process parent rgs python proc

import multiprocessing,threading
import time
import os

def threading_run():
print("線程ID",threading.get_ident())
t=threading.Thread(target=threading_run)

def info(title):
print(title)
print(‘module name:‘,__name__)
print("parent process:",os.getppid())
print("process id:",os.getpid())

def f(name):
time.sleep(1)
info("\033[31;1mfunction f\033[m")
print("Hello !",name)
t.start()

if __name__ == ‘__main__‘:
info(‘\033[32;1m main process line \033[0m]‘)
for i in range(5):
p = multiprocessing.Process(target=f,args=("bob"+ str(i),))
p.start()
p.join()

Python 進程