chainlet.concurrency.thread module

Thread based concurrency domain

Primitives of this module implement concurrency based on threads. This allows blocking actions, such as I/O and certain extension modules, to be run in parallel. Note that regular Python code is not parallelised by threads due to the Global Interpreter Lock. See the threading module for details.

warning:The primitives in this module should not be used manually, and may change without deprecation warning. Use convert() instead.
class chainlet.concurrency.thread.ThreadBundle(elements)

Bases: chainlet.concurrency.base.ConcurrentBundle

chain_types = <chainlet.concurrency.thread.ThreadLinkPrimitives object>
executor = <chainlet.concurrency.thread.ThreadPoolExecutor object>
class chainlet.concurrency.thread.ThreadChain(elements)

Bases: chainlet.concurrency.base.ConcurrentChain

chain_types = <chainlet.concurrency.thread.ThreadLinkPrimitives object>
executor = <chainlet.concurrency.thread.ThreadPoolExecutor object>
class chainlet.concurrency.thread.ThreadLinkPrimitives

Bases: chainlet.chainlink.LinkPrimitives

base_bundle_type

alias of ThreadBundle

base_chain_type

alias of ThreadChain

flat_chain_type

alias of ThreadChain

class chainlet.concurrency.thread.ThreadPoolExecutor(max_workers, identifier='')

Bases: chainlet.concurrency.base.LocalExecutor

Executor for futures using a pool of threads

Parameters:
  • max_workers (int or float) – maximum number of threads in pool
  • identifier (str) – base identifier for all workers
submit(call, *args, **kwargs)

Submit a call for future execution

Returns:future for the call execution
Return type:StoredFuture
chainlet.concurrency.thread.convert(element)

Convert a regular chainlink to a thread based version

Parameters:element – the chainlink to convert
Returns:a threaded version of element if possible, or the element itself