diff --git a/README.md b/README.md index 256edce..62e04f5 100644 --- a/README.md +++ b/README.md @@ -2130,36 +2130,32 @@ with : # Enters the block by calling acq = Barrier(n_times) # Wait() blocks until it's called n_times. ``` -### Thread Pool Executor -* **Object that manages thread execution.** -* **An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be [pickable](#pickle).** - +### Queue ```python - = ThreadPoolExecutor(max_workers=None) # Or: `with ThreadPoolExecutor() as : …` -.shutdown(wait=True) # Blocks until all threads finish executing. + = queue.Queue(maxsize=0) # A thread-safe FIFO queue. Also LifoQueue. +.put() # Blocks until queue stops being full. +.put_nowait() # Raises queue.Full exception if full. + = .get() # Blocks until queue stops being empty. + = .get_nowait() # Raises queue.Empty exception if empty. ``` +### Thread Pool Executor ```python - = .map(, , ...) # A multithreaded and non-lazy map(). + = ThreadPoolExecutor(max_workers=None) # Or: `with ThreadPoolExecutor() as : …` + = .map(, , ...) # A multithreaded non-lazy map(). Keeps order. = .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 -**A thread-safe FIFO queue. For LIFO queue use LifoQueue.** -```python -from queue import Queue - = Queue(maxsize=0) +.shutdown(wait=True) # Blocks until all threads finish executing. ``` ```python -.put() # Blocks until queue stops being full. -.put_nowait() # Raises queue.Full exception if full. - = .get() # Blocks until queue stops being empty. - = .get_nowait() # Raises queue.Empty exception if empty. + = .done() # Checks if the thread has finished executing. + = .result(timeout=None) # Waits for thread to finish and returns result. + = .cancel() # Returns False if thread is already running. + = as_completed() # Each Future is yielded as it completes. ``` +* **Map() and as_completed() also accept 'timeout' argument that causes TimeoutError if result isn't available in 'timeout' seconds after next() is called.** +* **Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. It's exception() method returns exception or None.** +* **An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. Arguments and results must be [pickable](#pickle).** Operator diff --git a/index.html b/index.html index 3774614..73f328a 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1762,30 +1762,29 @@ CompletedProcess(args=['bc', # Wait() blocks until it's called n_times. -

Thread Pool Executor

    -
  • Object that manages thread execution.
  • -
  • An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be pickable.
  • -
<Exec> = ThreadPoolExecutor(max_workers=None)  # Or: `with ThreadPoolExecutor() as <name>: …`
-<Exec>.shutdown(wait=True)                     # Blocks until all threads finish executing.
+

Queue

<Queue> = queue.Queue(maxsize=0)               # A thread-safe FIFO queue. Also LifoQueue.
+<Queue>.put(<el>)                              # Blocks until queue stops being full.
+<Queue>.put_nowait(<el>)                       # Raises queue.Full exception if full.
+<el> = <Queue>.get()                           # Blocks until queue stops being empty.
+<el> = <Queue>.get_nowait()                    # Raises queue.Empty exception if empty.
 
- -
<iter> = <Exec>.map(<func>, <args_1>, ...)     # A multithreaded and non-lazy map().
+

Thread Pool Executor

<Exec> = ThreadPoolExecutor(max_workers=None)  # Or: `with ThreadPoolExecutor() as <name>: …`
+<iter> = <Exec>.map(<func>, <args_1>, ...)     # A multithreaded non-lazy map(). Keeps order.
 <Futr> = <Exec>.submit(<func>, <arg_1>, ...)   # 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)
+<Exec>.shutdown(wait=True)                     # Blocks until all threads finish executing.
 
- -
<Queue>.put(<el>)                              # Blocks until queue stops being full.
-<Queue>.put_nowait(<el>)                       # Raises queue.Full exception if full.
-<el> = <Queue>.get()                           # Blocks until queue stops being empty.
-<el> = <Queue>.get_nowait()                    # Raises queue.Empty exception if empty.
+
<bool> = <Future>.done()                       # Checks if the thread has finished executing.
+<obj>  = <Future>.result(timeout=None)         # Waits for thread to finish and returns result.
+<bool> = <Future>.cancel()                     # Returns False if thread is already running.
+<iter> = as_completed(<coll_of_Futures>)       # Each Future is yielded as it completes.
 
+
    +
  • Map() and as_completed() also accept 'timeout' argument that causes TimeoutError if result isn't available in 'timeout' seconds after next() is called.
  • +
  • Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. It's exception() method returns exception or None.
  • +
  • An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. Arguments and results must be pickable.
  • +

#Operator

Module of functions that provide the functionality of operators.

import operator as op
 <obj>     = op.add/sub/mul/truediv/floordiv/mod(<obj>, <obj>)     # +, -, *, /, //, %
 <int/set> = op.and_/or_/xor(<int/set>, <int/set>)                 # &, |, ^
@@ -2936,7 +2935,7 @@ $ pyinstaller script.py --add-data '<path>:.'