Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced content levelIntermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
使用執行緒的程式架構
|
469
wait wait(fs, timeout=None, return_when=ALL_COMPLETED)
等候是迭代器
fs
的項目的
Future
實體。回傳一個具名的,由
set
組成的雙項目元組:第一個
set
,名為
done
,含有在
wait
回傳前
已完成的未來值(代表它們要不是執行完畢就是被取消了)。第二
set
,名為
not_done
,含有尚未完成的未來值。
timeout
,如果不為
None
,就是一個
float
秒數,即回傳前
wait
候的最長時間(當
timeout
None
wait
只會在
return_when
滿足
的時候回傳,不管那發生前經過了多久的時間)。
return_when
控制
wait
何時回傳;它必須是模組
concurrent.
futures
所提供的三個常數之一:
ALL_COMPLETED
在所有的未來值執行完畢或被取消時回傳
FIRST_COMPLETED
在任何的未來值執行完畢或被取消時回傳
FIRST_EXCEPTION
在有任何的未來值提出一個例外時回傳;如果沒有任何未來值
提出一個例外,就等同於
ALL_COMPLETED
使用執行緒的程式架構
一個分緒的程式(threaded program)應該永遠都試著安排
單一個
執行緒來
處理對程式來說算是外部的任何給定的物件或子系統(例如一個檔案、資
料庫、GUI 或網路連線)。讓多個執行緒處理相同的外部物件是可能的,
但通常會導致麻煩的問題。
當你的分緒程式必須處理某個外部物件,就設置一個專用的執行緒來進行
這種處理,使用一個 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

測試驅動開發|使用 Python

測試驅動開發|使用 Python

Harry J.W. Percival
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9789864766819