Improve docstring for Task.close and Task.mark_completed

This commit is contained in:
Richard Leibrandt 2023-02-21 16:39:47 +01:00
parent aa69f45d3b
commit 017dc4c784
2 changed files with 17 additions and 6 deletions

View File

@ -674,15 +674,23 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
def mark_completed(self, ignore_errors=True, status_message=None, force=False):
# type: (bool, Optional[str], bool) -> ()
"""
Use this function to close and change status of remotely executed tasks.
Closes the current Task, changes its status to "Completed", and terminates the running Python process.
This is in contrast to :meth:`Task.close`, which does the first two steps, but does not terminate the running Python process.
Use this method to close and change status of (remotely!) executed tasks.
This method closes the task it is a member of,
changes its status to "Completed", and
terminates the Python process that created the task.
This is in contrast to :meth:`Task.close`, which does the first two steps, but does not terminate any Python process.
Let's say that process A created the task and process B has a handle on the task, e.g., with :meth:`Task.get_task`.
Then, if we call :meth:`Task.mark_completed`, the process A is terminated, but process B is not.
However, if :meth:`Task.mark_completed` was called from the same process in which the task was created,
then - effectively - the process terminates itself.
For example, in
.. code-block:: py
task = Task.init(...)
task.mark_completed()
from time import sleep
sleep(30)

View File

@ -1725,8 +1725,11 @@ class Task(_Task):
def close(self):
"""
Closes the current Task and changes its status to "Completed".
Enables you to manually shut down the task.
This method does not terminate the current Python process, in contrast to :meth:`Task.mark_completed`.
Enables you to manually shut down the task from the process which opened the task.
This method does not terminate the (current) Python process, in contrast to :meth:`Task.mark_completed`.
Note, that if :meth:`Task.mark_completed` is called from a different process it will not terminate
the process from which :meth:`Task.mark_completed` was called, but the process which created the task.
After having :meth:`Task.close` -d a task, the respective object cannot be used anymore and
methods like :meth:`Task.connect` or :meth:`Task.connect_configuration` will throw a `ValueError`.