Tümü Yeni

user:thomas kullanıcı tarafından oluşturulan gistler

title:mygist belirtilen isme sahip gistler

filename:myfile.txt belirtilen isimde dosyaları olan gistler

extension:yml belirtilen uzantıya sahip dosyalara sahip gistler

language:go belirtilen dilde dosyaları olan gistler

topic:homelab Verilen konuyla ilgili gist'ler

Giriş


Tümü Yeni Giriş

Konuyla eşleşen tüm gist'ler concurrency

Yakın zamanda oluşturuldu
En eski oluşturuldu
Yakın zamanda güncellendi
En eski güncellendi

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

0 beğeniler
0 çatallar
1 dosyalar
Son aktivite 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:

timmy / 使用 multiprocessing.Pipe 進行進程間通訊

0 beğeniler
0 çatallar
1 dosyalar
Son aktivite 9 months ago
multiprocessing.Pipe 允許 Python 進程之間傳遞資料,適用於需要高效能、雙向通訊的場景,如併發運算或分佈式處理。
concurrency ipc multiprocessing parallel-processing pipe python
1 from multiprocessing import Process, Pipe
2
3 def worker(conn):
4 conn.send("Hello from child process") # 傳送訊息
5 msg = conn.recv() # 接收訊息
6 print(f"Child received: {msg}")
7 conn.close()
8
9 if __name__ == "__main__":
10 parent_conn, child_conn = Pipe() # 建立 Pipe 雙向通道
Daha yeni Daha eski

Opengist tarafından desteklenmektedir ⋅ Load: 42ms⋅

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