Update docs.
authorScott Gasch <[email protected]>
Sun, 30 Oct 2022 20:50:50 +0000 (13:50 -0700)
committerScott Gasch <[email protected]>
Sun, 30 Oct 2022 20:50:50 +0000 (13:50 -0700)
docs/pyutils.collectionz.rst
src/pyutils/parallelize/parallelize.py
src/pyutils/parallelize/smart_future.py

index 0b0123797f7cfa159ea5b0f58aebed67830a3347..5ca878d6b9ed1f59c948988f689201f9cfb0e8e3 100644 (file)
@@ -1,9 +1,12 @@
 pyutils.collectionz package
 ===========================
 
-This subpackage contains some homegrown collections that try to emulate
-:mod:`collections` included in the Python standard library.  It ends
-with a 'z' so as not to collide with the standard library package.
+This subpackage contains some homegrown collections that try to
+emulate :mod:`collections` included in the Python standard library
+(see:
+https://docs.python.org/3/library/collections.html#module-collections).
+It ends with a 'z' so as not to collide with the standard library
+package.
 
 Submodules
 ----------
index 515d431dea4e4fa8c7c4101a0573d4308990c0e5..7071ef337269951dfb5fcf5eb828d1313441dc6d 100644 (file)
@@ -12,10 +12,12 @@ remote machine depending on the style of decoration::
     def my_function(a, b, c) -> int:
         ...do some slow / expensive work, e.g., an http request
 
+    # Run with background subprocess
     @p.parallelize(method=Method.PROCESS)
     def my_other_function(d, e, f) -> str:
         ...do more really expensive work, e.g., a network read
 
+    # Run in a helper process on another machine.
     @p.parallelize(method=Method.REMOTE)
     def my_other_other_function(g, h) -> int:
         ...this work will be distributed to a remote machine pool
@@ -72,6 +74,31 @@ do some setup work:
     If you're trying to set this up and struggling, email me at
     [email protected].  I'm happy to help.
 
+    What you get back when you call a decorated message is a
+    :class:`pyutils.parallelize.smart_future.SmartFuture`.  This class
+    attempts to transparently wrap a normal Python :class:`Future`
+    (see
+    https://docs.python.org/3/library/concurrent.futures.html#future-objects).
+    If your code just uses the result of a `parallelized` method it
+    will block waiting on the result of the method as soon as it uses
+    the result in a manner that requires its value to be known
+    (e.g. using it in an expression, calling a method on it, hashing
+    it, etc...)  But you can do operations that do not require the
+    value to be known (e.g. storing it in a list, storing it as a
+    value in a dict, etc...) without blocking.
+
+    There are two helper methods in
+    :mod:`pyutils.parallelize.smart_future` to help deal with these
+    :class:`SmartFuture` objects called
+    :meth:`pyutils.parallelize.smart_future.wait_all` and
+    :meth:`pyutils.parallelize.smart_future.wait_any`.  These, when
+    given a collection of :class:`SmartFuture` objects,
+    will block until one (any) or all (all) are finished and yield the
+    finished objects to the caller.  Callers can be confident that any
+    objects returned from these methods will not block when accessed.
+    See documentation in :mod:`pyutils.parallelize.smart_future` for
+    more details.
+
 """
 
 import atexit
index 8ac05f1b0eb9184b9c9cf1f596020686371082a3..b722cfecb5d6e4b525bf5770ae1014634fd5d787 100644 (file)
@@ -50,7 +50,7 @@ def wait_any(
             futures completes
         log_exceptions: Should we log (warning + exception) any
             underlying exceptions raised during future processing or
-            silently ignore then?
+            silently ignore them?
         timeout: invoke callback with a periodicity of timeout while
             awaiting futures
 
@@ -105,7 +105,7 @@ def wait_all(
         futures: A collection of futures that we're waiting for
         log_exceptions: Should we log (warning + exception) any
             underlying exceptions raised during future processing or
-            silently ignore then?
+            silently ignore them?
 
     Returns:
         Only when all futures in the input list are ready.  Blocks