From f32d13ea7a032396e26d76483d6b562da0ca9513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 25 Dec 2022 05:19:17 +0100 Subject: [PATCH] Threading --- README.md | 3 ++- index.html | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2b797e8..eca522d 100644 --- a/README.md +++ b/README.md @@ -2092,7 +2092,7 @@ Threading * **That is why using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.** ```python from threading import Thread, RLock, Semaphore, Event, Barrier -from concurrent.futures import ThreadPoolExecutor +from concurrent.futures import ThreadPoolExecutor, as_completed ``` ### Thread @@ -2139,6 +2139,7 @@ with : # Enters the block by calling acq = .submit(, , ...) # Starts a thread and returns its Future object. = .done() # Checks if the thread has finished executing. = .result() # Waits for thread to finish and returns result. + = as_completed() # Each Future is yielded as it completes. ``` ### Queue diff --git a/index.html b/index.html index f8dd7b7..5612ba3 100644 --- a/index.html +++ b/index.html @@ -1731,7 +1731,7 @@ CompletedProcess(args=['bc', from threading import Thread, RLock, Semaphore, Event, Barrier -from concurrent.futures import ThreadPoolExecutor +from concurrent.futures import ThreadPoolExecutor, as_completed @@ -1771,6 +1771,7 @@ CompletedProcess(args=['bc', # Starts a thread and returns its Future object. <bool> = <Futr>.done() # Checks if the thread has finished executing. <obj> = <Futr>.result() # Waits for thread to finish and returns result. +<iter> = as_completed(<coll_of_Futr>) # Each Future is yielded as it completes.

Queue

A thread-safe FIFO queue. For LIFO queue use LifoQueue.

from queue import Queue
 <Queue> = Queue(maxsize=0)