用法:
wait(timeout=None)
通過障礙。當屏障的所有線程都調用了這個函數時,它們都被同時釋放。如果提供了
timeout
,則它優先於提供給類構造函數的任何內容使用。返回值是 0 到
parties
- 1 範圍內的整數,每個線程都不同。這可以用來選擇一個線程來做一些特殊的家務,例如:i = barrier.wait() if i == 0: # Only one thread needs to print this print("passed the barrier")
如果向構造函數提供了
action
,則其中一個線程將在釋放之前調用它。如果此調用引發錯誤,則屏障將進入損壞狀態。如果調用超時,屏障將進入破壞狀態。
如果在線程等待時屏障被破壞或重置,此方法可能會引發
BrokenBarrierError
異常。
相關用法
- Python threading get_native_id()用法及代碼示例
- Python threading enumerate()用法及代碼示例
- Python threading get_ident()用法及代碼示例
- Python threading active_count()用法及代碼示例
- Python threading main_thread()用法及代碼示例
- Python threading stack_size()用法及代碼示例
- Python threading current_thread()用法及代碼示例
- Python threading setprofile()用法及代碼示例
- Python threading settrace()用法及代碼示例
- Python torch.distributed.rpc.rpc_async用法及代碼示例
- Python torch.nn.InstanceNorm3d用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python torchaudio.transforms.Fade用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.summary.scalar用法及代碼示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代碼示例
- Python tf.raw_ops.TPUReplicatedInput用法及代碼示例
- Python tf.raw_ops.Bitcast用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 threading.Barrier.wait。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。