python的进程,线程、协程

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())
相关推荐
SelectDB8 小时前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python
Flittly9 小时前
【AgentScope Java新手村系列】(16)从RAG到多路检索
java·spring boot·spring
小兔崽子去哪了9 小时前
Java 生成二维码解决方案
java·后端
人活一口气14 小时前
从JVM调优到MCP协议:Java全栈技术体系深度总结与企业级架构实践
java·spring boot
NE_STOP16 小时前
Vibe Coding -- 完整项目案例实操
java
荣码16 小时前
GraphRAG:普通RAG只能回答"点"的问题,我踩了4个坑才搞懂
java·python
SimonKing16 小时前
Google第三方授权登录
java·后端·程序员
明月光81816 小时前
从一行 @Builder 说起:重新拾起 Java 的 Lombok、注解与 Builder 模式
java
考虑考虑1 天前
Mybatis实现批量插入
java·后端·mybatis
咖啡八杯1 天前
GoF设计模式——中介者模式
java·后端·spring·设计模式