Skip to main content

Result and friends.

A Result is the base class for several callable subclasses which will receive values at a later point in time, and can also be used standalone without subclassing.

A call to a Result will block until the value is received or the Result is cancelled, which will raise an exception in the caller. A Result may be called by multiple users, before or after the value has been delivered; if the value has been delivered the caller returns with it immediately. A Result's state may be inspected (pending, running, ready, cancelled). Callbacks can be registered via a Result's .notify method.

An incomplete Result can be told to call a function to compute its value; the function return will be stored as the value unless the function raises an exception, in which case the exception information is recorded instead. If an exception occurred, it will be reraised for any caller of the Result.

Trite example::

R = Result(name="my demo")

Thread 1: value = R() # blocks... print(value) # prints 3 once Thread 2 (below) assigns to it

Thread 2: R.result = 3

Thread 3: value = R() # returns immediately with 3

You can also collect multiple Results in completion order using the report() function::

Rs = [ ... list of Results of whatever type ... ] ... for R in report(Rs): x = R() # collect result, will return immediately because # the Result is complete print(x) # print result

Function after(Rs, R, func, *a, **kw)

After the completion of Rs call func(*a, **kw) and return its result via R; return the Result object.

Rs: an iterable of Results. R: a Result to collect to result of calling func. If None, one will be created. func, a, kw: a callable and its arguments.

Class AsynchState

MRO: enum.Enum
State tokens for Results.

Function bg(func, *a, **kw)

Dispatch a Thread to run func, return a Result to collect its value.

Class CancellationError

MRO: builtins.Exception, builtins.BaseException
Raised when accessing result or exc_info after cancellation.

Class OnDemandFunction

MRO: Result
Wrap a callable, run it when required.

Class OnDemandResult

MRO: Result
Wrap a callable, run it when required.

Function report(LFs)

Generator which yields completed Results. This is a generator that yields Results as they complete, useful for waiting for a sequence of Results that may complete in an arbitrary order.

Class Result

Basic class for asynchronous collection of a result. This is also used to make OnDemandFunctions, LateFunctions and other objects with asynchronous termination.

Class ResultState

MRO: enum.Enum
State tokens for Results.

Release files for cs-result 20190522

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs-result 20190522
File Size Uploaded
cs.result-20190522.tar.gz 6.6 kB Details

Release files / cs.result-20190522.tar.gz

Download URL cs.result-20190522.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8a83e0bc8412799c659849535ecceb24d0bcb7c682ff38d5275199bb262605d8
BLAKE2b-256 checksum
How to use checksums
8505d93be8d0446ecf36ac1cdb29724a08f769d0b68c29a9d172a9d8f8421d6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page