bittensor.threadpool#

Implements ThreadPoolExecutor.

Attributes#

Exceptions#

Classes#

_WorkItem

PriorityThreadPoolExecutor

Base threadpool executor with a priority queue

Functions#

_worker(executor_reference, work_queue, initializer, ...)

Module Contents#

bittensor.threadpool.__author__ = 'Brian Quinlan (brian@sweetapp.com)'#
bittensor.threadpool.logger#
bittensor.threadpool._threads_queues#
bittensor.threadpool._shutdown = False#
class bittensor.threadpool._WorkItem(future, fn, start_time, args, kwargs)[source]#

Bases: object

future#
fn#
start_time#
args#
kwargs#
run()[source]#

Run the given work item

bittensor.threadpool.NULL_ENTRY#
bittensor.threadpool._worker(executor_reference, work_queue, initializer, initargs)[source]#
exception bittensor.threadpool.BrokenThreadPool[source]#

Bases: concurrent.futures._base.BrokenExecutor

Raised when a worker thread in a ThreadPoolExecutor failed initializing.

Initialize self. See help(type(self)) for accurate signature.

class bittensor.threadpool.PriorityThreadPoolExecutor(maxsize=-1, max_workers=None, thread_name_prefix='', initializer=None, initargs=())[source]#

Bases: concurrent.futures._base.Executor

Base threadpool executor with a priority queue

Initializes a new ThreadPoolExecutor instance.

Parameters:
  • max_workers – The maximum number of threads that can be used to execute the given calls.

  • thread_name_prefix – An optional name prefix to give our threads.

  • initializer – An callable used to initialize worker threads.

  • initargs – A tuple of arguments to pass to the initializer.

_counter#
_max_workers#
_work_queue#
_idle_semaphore#
_threads#
_broken = False#
_shutdown = False#
_shutdown_lock#
_thread_name_prefix#
_initializer#
_initargs#
classmethod add_args(parser, prefix=None)[source]#

Accept specific arguments from parser

Parameters:
classmethod config()[source]#

Get config from the argument parser.

Return: bittensor.config() object.

Return type:

bittensor.config

property is_empty#
submit(fn, *args, **kwargs)[source]#

Submits a callable to be executed with the given arguments.

Schedules the callable to be executed as fn(*args, **kwargs) and returns a Future instance representing the execution of the callable.

Returns:

A Future representing the given call.

Parameters:

fn (Callable)

Return type:

concurrent.futures._base.Future

_adjust_thread_count()[source]#
_initializer_failed()[source]#
shutdown(wait=True)[source]#

Clean-up the resources associated with the Executor.

It is safe to call this method several times. Otherwise, no other methods can be called after this one.

Parameters:
  • wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.

  • cancel_futures – If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.