python进程的实现
#coding:utf-8
from multiprocessing import Process
import time
def run(name):
print('%s is running' % name)
time.sleep(3)
print('%s finished his run' % name)
if __name__ == '__main__':
p = Process(target=run, args=('XWenXiang',)) # 创建一个进程对象
p.start() # 告诉操作系统创建一个新的进程
print('父进程')
python线程的实现
python协程实现的代码
(协程是在线程的基础上进一步切换)
#coding:utf-8
import asyncio
async def hello():
print("Hello")
await asyncio.sleep(3) # 模拟耗时操作
print("World")
asyncio.run(hello())