diff --git a/README.md b/README.md index 8016854..ef0f117 100644 --- a/README.md +++ b/README.md @@ -1170,7 +1170,8 @@ Hello World! with open('') as file: ... with wave.open('') as wave_file: ... with memoryview() as view: ... -db = sqlite3.connect(''); with db: db.execute('') +with concurrent.futures.ThreadPoolExecutor() as executor: ... +db = sqlite3.connect(''); with db: ... lock = threading.RLock(); with lock: ... ``` @@ -1982,6 +1983,13 @@ with lock: ... ``` +### Thread Pool +```python +from concurrent.futures import ThreadPoolExecutor +with ThreadPoolExecutor(max_workers=None) as executor: + results = executor.map(lambda x: x + 1, range(3)) # (1, 2, 3) +``` + Introspection ------------- diff --git a/index.html b/index.html index b32946c..5c382ac 100644 --- a/index.html +++ b/index.html @@ -1101,7 +1101,8 @@ Hello World!

List of existing context managers:

with open('<path>') as file: ...
 with wave.open('<path>') as wave_file: ...
 with memoryview(<bytes/bytearray/array>) as view: ...
-db = sqlite3.connect('<path>'); with db: db.execute('<insert_query>')
+with concurrent.futures.ThreadPoolExecutor() as executor: ...
+db = sqlite3.connect('<path>'); with db: ...
 lock = threading.RLock(); with lock: ...
 
@@ -1740,6 +1741,11 @@ lock.release() ... +

Thread Pool

from concurrent.futures import ThreadPoolExecutor
+with ThreadPoolExecutor(max_workers=None) as executor:
+    results = executor.map(lambda x: x + 1, range(3))   # (1, 2, 3)
+
+

#Introspection

Inspecting code at runtime.

Variables

<list> = dir()      # Names of variables in current scope.
 <dict> = locals()   # Dict of local variables. Also vars().
 <dict> = globals()  # Dict of global variables.