Všechno Nové

user:thomas gists created by user

title:mygist gists with given title

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

Přihlásit se


Všechno Nové Přihlásit se

All gists matching topic threadpool

Nedávno Vytvořeno
Nejméně nedávno Vytvořeno
Nedávno Aktualizováno
Nejméně nedávno Aktualizováno

timmy / 使用 ThreadPoolExecutor 進行多執行緒任務管理

0 Lajky
0 Forky
1 Soubory
Naposledy aktivní 9 months ago
ThreadPoolExecutor 提供了一種簡單的方式來管理多執行緒,適用於 I/O 密集型任務(如網路請求、檔案處理、資料庫查詢),提高執行效率。
concurrency parallelism python threading threadpool
1 from concurrent.futures import ThreadPoolExecutor, as_completed
2 import time
3
4 def task(n):
5 """模擬一個耗時任務"""
6 time.sleep(n)
7 return f"Task {n} completed after {n} seconds"
8
9 # 建立執行緒池
10 with ThreadPoolExecutor(max_workers=3) as executor:
Novější Starší

Vytvořeno pomocí Opengist ⋅ Load: 22ms⋅

Čeština
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文