TaskPool

class TaskPool(**properties: Any)

Superclasses: Object, InitiallyUnowned, Object

Subclasses: SharedTaskPool

This object provides an abstraction for creating threads. The default implementation uses a regular GThreadPool to start tasks.

Subclasses can be made to create custom threads.

Constructors

class TaskPool
classmethod new() TaskPool

Create a new default task pool. The default task pool will use a regular GThreadPool for threads.

Methods

class TaskPool
cleanup() None

Wait for all tasks to be stopped. This is mainly used internally to ensure proper cleanup of internal data structures in test suites.

MT safe.

dispose_handle(id: None) None

Dispose of the handle returned by push(). This does not need to be called with the default implementation as the default TaskPoolClass::push implementation always returns None. This does not need to be called either when calling join(), but should be called when joining is not necessary, but push() returned a non-None value.

This method should only be called with the same pool instance that provided id.

Added in version 1.20.

Parameters:

id – the id

join(id: None) None

Join a task and/or return it to the pool. id is the id obtained from push(). The default implementation does nothing, as the default TaskPoolClass::push implementation always returns None.

This method should only be called with the same pool instance that provided id.

Parameters:

id – the id

prepare() None

Prepare the taskpool for accepting push() operations.

MT safe.

push(func: Callable[[...], None], *user_data: Any) None

Start the execution of a new thread from pool.

Parameters:
  • func – the function to call

  • user_data – data to pass to func

Virtual Methods

class TaskPool
do_cleanup() None

Wait for all tasks to be stopped. This is mainly used internally to ensure proper cleanup of internal data structures in test suites.

MT safe.

do_dispose_handle(id: None) None

Dispose of the handle returned by push(). This does not need to be called with the default implementation as the default TaskPoolClass::push implementation always returns None. This does not need to be called either when calling join(), but should be called when joining is not necessary, but push() returned a non-None value.

This method should only be called with the same pool instance that provided id.

Added in version 1.20.

Parameters:

id – the id

do_join(id: None) None

Join a task and/or return it to the pool. id is the id obtained from push(). The default implementation does nothing, as the default TaskPoolClass::push implementation always returns None.

This method should only be called with the same pool instance that provided id.

Parameters:

id – the id

do_prepare() None

Prepare the taskpool for accepting push() operations.

MT safe.

do_push(func: Callable[[...], None], *user_data: Any) None

Start the execution of a new thread from pool.

Parameters:
  • func – the function to call

  • user_data – data to pass to func

Fields

class TaskPool
object
pool