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: Any = 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_cleanup(self) None#
do_dispose_handle(self, id: Any = None) None#
Parameters:

id

do_join(self, id: Any = None) None#
Parameters:

id

do_prepare(self) None#
do_push(self, func: Callable[[Any], None], user_data: Any = None) Any | None#
Parameters:
  • func

  • user_data

join(id: Any = 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[[Any], None], user_data: Any = None) 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: Any = 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: Any = 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[[Any], None], user_data: Any = None) 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#