:right-sidebar: True Task =================================================================== .. currentmodule:: gi.repository.Gst .. class:: Task(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gst.Object`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` :Constructors: :: Task(**properties) new(func:Gst.TaskFunction, user_data=None) -> Gst.Task Constructors ------------ .. rst-class:: interim-class .. class:: Task :no-index: .. classmethod:: new(func: ~typing.Callable[[...], None], *user_data: ~typing.Any) -> ~gi.repository.Gst.Task Create a new Task that will repeatedly call the provided ``func`` with ``user_data`` as a parameter. Typically the task will run in a new thread. The function cannot be changed after the task has been created. You must create a new :obj:`~gi.repository.Gst.Task` to change the function. This function will not yet create and start a thread. Use :func:`~gi.repository.Gst.Task.start` or :func:`~gi.repository.Gst.Task.pause` to create and start the GThread. Before the task can be used, a :obj:`~gi.repository.GLib.RecMutex` must be configured using the :func:`~gi.repository.Gst.Task.set_lock` function. This lock will always be acquired while ``func`` is called. :param func: The :obj:`~gi.repository.Gst.TaskFunction` to use :param user_data: User data to pass to ``func`` Methods ------- .. rst-class:: interim-class .. class:: Task :no-index: .. method:: cleanup_all() -> 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. .. method:: get_pool() -> ~gi.repository.Gst.TaskPool Get the :obj:`~gi.repository.Gst.TaskPool` that this task will use for its streaming threads. MT safe. .. method:: get_state() -> ~gi.repository.Gst.TaskState Get the current state of the task. .. method:: join() -> bool Joins ``task``. After this call, it is safe to unref the task and clean up the lock set with :func:`~gi.repository.Gst.Task.set_lock`. The task will automatically be stopped with this call. This function cannot be called from within a task function as this would cause a deadlock. The function will detect this and print a g_warning. .. method:: pause() -> bool Pauses ``task``. This method can also be called on a task in the stopped state, in which case a thread will be started and will remain in the paused state. This function does not wait for the task to complete the paused state. .. method:: resume() -> bool Resume ``task`` in case it was paused. If the task was stopped, it will remain in that state and this function will return :const:`False`. .. versionadded:: 1.18 .. method:: set_enter_callback(enter_func: ~typing.Callable[[...], None], *user_data: ~typing.Any) -> None Call ``enter_func`` when the task function of ``task`` is entered. ``user_data`` will be passed to ``enter_func`` and ``notify`` will be called when ``user_data`` is no longer referenced. :param enter_func: a :obj:`~gi.repository.Gst.TaskThreadFunc` :param user_data: user data passed to ``enter_func`` .. method:: set_leave_callback(leave_func: ~typing.Callable[[...], None], *user_data: ~typing.Any) -> None Call ``leave_func`` when the task function of ``task`` is left. ``user_data`` will be passed to ``leave_func`` and ``notify`` will be called when ``user_data`` is no longer referenced. :param leave_func: a :obj:`~gi.repository.Gst.TaskThreadFunc` :param user_data: user data passed to ``leave_func`` .. method:: set_lock(mutex: ~gi.repository.GLib.RecMutex) -> None Set the mutex used by the task. The mutex will be acquired before calling the :obj:`~gi.repository.Gst.TaskFunction`. This function has to be called before calling :func:`~gi.repository.Gst.Task.pause` or :func:`~gi.repository.Gst.Task.start`. MT safe. :param mutex: The :obj:`~gi.repository.GLib.RecMutex` to use .. method:: set_pool(pool: ~gi.repository.Gst.TaskPool) -> None Set ``pool`` as the new GstTaskPool for ``task``. Any new streaming threads that will be created by ``task`` will now use ``pool``. MT safe. :param pool: a :obj:`~gi.repository.Gst.TaskPool` .. method:: set_state(state: ~gi.repository.Gst.TaskState) -> bool Sets the state of ``task`` to ``state``. The ``task`` must have a lock associated with it using :func:`~gi.repository.Gst.Task.set_lock` when going to GST_TASK_STARTED or GST_TASK_PAUSED or this function will return :const:`False`. MT safe. :param state: the new task state .. method:: start() -> bool Starts ``task``. The ``task`` must have a lock associated with it using :func:`~gi.repository.Gst.Task.set_lock` or this function will return :const:`False`. .. method:: stop() -> bool Stops ``task``. This method merely schedules the task to stop and will not wait for the task to have completely stopped. Use :func:`~gi.repository.Gst.Task.join` to stop and wait for completion. Fields ------ .. rst-class:: interim-class .. class:: Task :no-index: .. attribute:: cond Used to pause/resume the task .. attribute:: func The function executed by this task .. attribute:: lock The lock taken when iterating the task function .. attribute:: notify GDestroyNotify for ``user_data`` .. attribute:: object .. attribute:: priv .. attribute:: running A flag indicating that the task is running .. attribute:: state The state of the task .. attribute:: thread .. attribute:: user_data User_data passed to the task function