python多进程
使用multiprocessing包,demo
#!/usr/bin/python3 import os import time import multiprocessing def drink(): print("drink pid, ppid", os.getpid(), os.getppid()) for i in range(3): print("drink...") time.sleep(1) def eat(): print("eat process pid, ppid", os.getpid(), os.getppid()) for i in range(3): print("eat...") time.sleep(1) if __name__ == '__main__': drink_process = multiprocessing.Process(target=drink) eat_process = multiprocessing.Process(target=eat) print("cpu core num: ", os.cpu_count()) print("main pid ", os.getpid()) drink_process.start() eat_process.start()
Please call me JiangYouDang!