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())
相关推荐
Lupino11 小时前
别再只聊 AI 写代码了:技术负责人要把“变更治理”提到第一优先级
python·docker·容器
NE_STOP11 小时前
MyBatis-plus进阶之映射与条件构造器
java
Flittly12 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(6)Context Compact (上下文压缩)
python·agent
Seven9714 小时前
NIO的零拷贝如何实现高效数据传输?
java
曲幽1 天前
FastAPI + PostgreSQL 实战:从入门到不踩坑,一次讲透
python·sql·postgresql·fastapi·web·postgres·db·asyncpg
用户8356290780511 天前
使用 C# 在 Excel 中创建数据透视表
后端·python
架构师沉默1 天前
别又牛逼了!AI 写 Java 代码真的行吗?
java·后端·架构
码路飞1 天前
FastMCP 实战:一个 .py 文件,给 Claude Code 装上 3 个超实用工具
python·ai编程·mcp
后端AI实验室1 天前
我把一个生产Bug的排查过程,交给AI处理——20分钟后我关掉了它
java·ai
dev派1 天前
AI Agent 系统中的常用 Workflow 模式(2) Evaluator-Optimizer模式
python·langchain