摘要: import asyncio import random import threading from concurrent.futures import ThreadPoolExecutor import time def blocking_task(x): time.sleep(2) thread 阅读全文
posted @ 2024-09-12 18:12 vx_guanchaoguo0 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 异步下载文件 async def download_file_with_curl(url: str, destination: str): curl_command = [ "curl", "-k", f"{url}", "-o", destination, ] process = await as 阅读全文
posted @ 2024-09-12 09:39 vx_guanchaoguo0 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 线程池 都在一个进程内 GIL 不适合密集型计算 共享进程资源,存在不安全的线程 from concurrent.futures import ThreadPoolExecutor def task(n): return n * 2 if __name__ == '__main__': with T 阅读全文
posted @ 2024-09-12 09:21 vx_guanchaoguo0 阅读(5) 评论(0) 推荐(0) 编辑