python进程的实现
#coding:utf-8 from multiprocessing import Process import timedef 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 asyncioasync def hello():print("Hello")await asyncio.sleep(3) # 模拟耗时操作print("World")asyncio.run(hello())