一、多个线程之间PID的区别
主进程跟线程的pid是一样的
from threading import Thread from multiprocessing import Process import os def task(): print(‘%s is running‘ %os.getpid()) if __name__ == ‘__main__‘: t1=Thread(target=task,) t2=Thread(target=task,) t1.start() t2.start() print(‘主‘,os.getpid())
输出:6700 is running6700 is running主 6700
二、多个进程PID的区别
多个进程的PID完全不一样
from threading import Thread from multiprocessing import Process import os def task(): print(‘%s is running‘ %os.getpid()) if __name__ == ‘__main__‘: t1=Process(target=task,) t2=Process(target=task,) t1.start() t2.start() print(‘主‘,os.getpid()) 输出: 主 2040 7104 is running 2768 is running
原文地址:https://www.cnblogs.com/xiechao621/p/8157809.html
时间: 2024-10-17 09:24:11