From 84ae7a35a9dcb303fdb808080413ee74819c7d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 4 Dec 2019 03:28:58 +0100 Subject: [PATCH] Threading --- README.md | 3 ++- index.html | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1383938..421bd22 100644 --- a/README.md +++ b/README.md @@ -2043,12 +2043,13 @@ with lock: ### Thread Pool Executor ```python from concurrent.futures import ThreadPoolExecutor -with ThreadPoolExecutor(max_workers=None) as executor: +with ThreadPoolExecutor(max_workers=None) as executor: # None == `n_cores * 5`. = executor.map(lambda x: x + 1, range(3)) # (1, 2, 3) = executor.map(lambda x, y: x + y, 'abc', '123') # ('a1', 'b2', 'c3') = executor.submit( [, , ...]) ``` +#### Future ```python = .done() # Checks if thread has finished executing. = .result() # Waits for thread to finish and returns result. diff --git a/index.html b/index.html index 44551c1..412347e 100644 --- a/index.html +++ b/index.html @@ -1799,15 +1799,16 @@ lock.release()

Thread Pool Executor

from concurrent.futures import ThreadPoolExecutor
-with ThreadPoolExecutor(max_workers=None) as executor:
+with ThreadPoolExecutor(max_workers=None) as executor:         # None == `n_cores * 5`.
     <iter>   = executor.map(lambda x: x + 1, range(3))         # (1, 2, 3)
     <iter>   = executor.map(lambda x, y: x + y, 'abc', '123')  # ('a1', 'b2', 'c3')
     <Future> = executor.submit(<function> [, <arg_1>, ...])
 
-
<bool> = <Future>.done()             # Checks if thread has finished executing.
+

Future

<bool> = <Future>.done()             # Checks if thread has finished executing.
 <obj>  = <Future>.result()           # Waits for thread to finish and returns result.
-
+
+

Queue

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

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