From 593a1e157fa8d2f191e5fa292502b9a7907d8b89 Mon Sep 17 00:00:00 2001 From: trgiangdo Date: Tue, 30 Jul 2024 10:57:55 +0700 Subject: [PATCH 1/2] fix: wait with no timeout should wait indefinitely --- taipy/core/_orchestrator/_orchestrator.py | 10 +++++++--- taipy/core/scenario/scenario.py | 1 + taipy/core/sequence/sequence.py | 1 + taipy/core/taipy.py | 1 + taipy/core/task/task.py | 1 + tests/core/_orchestrator/test_orchestrator__submit.py | 4 ++-- .../_orchestrator/test_orchestrator__submit_task.py | 2 +- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/taipy/core/_orchestrator/_orchestrator.py b/taipy/core/_orchestrator/_orchestrator.py index 7c6833b98e..d9fd92c00b 100644 --- a/taipy/core/_orchestrator/_orchestrator.py +++ b/taipy/core/_orchestrator/_orchestrator.py @@ -66,6 +66,7 @@ def submit( finished in asynchronous mode. timeout (Union[float, int]): The optional maximum number of seconds to wait for the jobs to be finished before returning. + If not provided and wait is True, the function waits indefinitely. **properties (dict[str, any]): A key worded variable length list of user additional arguments that will be stored within the `Submission^`. It can be accessed via `Submission.properties^`. Returns: @@ -97,7 +98,7 @@ def submit( if Config.job_config.is_development: cls._check_and_execute_jobs_if_development_mode() elif wait: - cls._wait_until_job_finished(jobs, timeout=timeout or 0) + cls._wait_until_job_finished(jobs, timeout) return submission @classmethod @@ -120,6 +121,7 @@ def submit_task( in asynchronous mode. timeout (Union[float, int]): The optional maximum number of seconds to wait for the job to be finished before returning. + If not provided and wait is True, the function waits indefinitely. **properties (dict[str, any]): A key worded variable length list of user additional arguments that will be stored within the `Submission^`. It can be accessed via `Submission.properties^`. Returns: @@ -145,7 +147,7 @@ def submit_task( cls._check_and_execute_jobs_if_development_mode() else: if wait: - cls._wait_until_job_finished(job, timeout=timeout or 0) + cls._wait_until_job_finished(job, timeout) return submission @classmethod @@ -199,9 +201,11 @@ def _orchestrate_job_to_run_or_block(cls, jobs: List[Job]) -> None: cls.jobs_to_run.put(job) @classmethod - def _wait_until_job_finished(cls, jobs: Union[List[Job], Job], timeout: float = 0) -> None: + def _wait_until_job_finished(cls, jobs: Union[List[Job], Job], timeout: Optional[Union[float, int]] = None) -> None: # Note: this method should be prefixed by two underscores, but it has only one, so it can be mocked in tests. def __check_if_timeout(st, to): + if to is None: + return True return (datetime.now() - st).seconds < to start = datetime.now() diff --git a/taipy/core/scenario/scenario.py b/taipy/core/scenario/scenario.py index 9334863826..28c28d1743 100644 --- a/taipy/core/scenario/scenario.py +++ b/taipy/core/scenario/scenario.py @@ -609,6 +609,7 @@ def submit( asynchronous mode. timeout (Union[float, int]): The optional maximum number of seconds to wait for the jobs to be finished before returning. + If not provided and wait is True, the function waits indefinitely. **properties (dict[str, any]): A keyworded variable length list of additional arguments. Returns: A `Submission^` containing the information of the submission. diff --git a/taipy/core/sequence/sequence.py b/taipy/core/sequence/sequence.py index 2efe14b9f1..03b6c95717 100644 --- a/taipy/core/sequence/sequence.py +++ b/taipy/core/sequence/sequence.py @@ -312,6 +312,7 @@ def submit( in asynchronous mode. timeout (Union[float, int]): The maximum number of seconds to wait for the jobs to be finished before returning. + If not provided and wait is True, the function waits indefinitely. **properties (dict[str, any]): A keyworded variable length list of additional arguments. Returns: A `Submission^` containing the information of the submission. diff --git a/taipy/core/taipy.py b/taipy/core/taipy.py index 50897d95a2..101787f25f 100644 --- a/taipy/core/taipy.py +++ b/taipy/core/taipy.py @@ -241,6 +241,7 @@ def submit( in asynchronous mode. timeout (Union[float, int]): The optional maximum number of seconds to wait for the jobs to be finished before returning. + If not provided and wait is True, the function waits indefinitely. **properties (dict[str, any]): A key-worded variable length list of user additional arguments that will be stored within the `Submission^`. It can be accessed via `Submission.properties^`. diff --git a/taipy/core/task/task.py b/taipy/core/task/task.py index cdb9884acc..03bf3bf2a1 100644 --- a/taipy/core/task/task.py +++ b/taipy/core/task/task.py @@ -232,6 +232,7 @@ def submit( mode. timeout (Union[float, int]): The maximum number of seconds to wait for the job to be finished before returning. + If not provided and wait is True, the function waits indefinitely. **properties (dict[str, any]): A keyworded variable length list of additional arguments. Returns: A `Submission^` containing the information of the submission. diff --git a/tests/core/_orchestrator/test_orchestrator__submit.py b/tests/core/_orchestrator/test_orchestrator__submit.py index e1ff25bf48..8b9111292b 100644 --- a/tests/core/_orchestrator/test_orchestrator__submit.py +++ b/tests/core/_orchestrator/test_orchestrator__submit.py @@ -320,7 +320,7 @@ def test_submit_scenario_with_callbacks_and_force_and_wait(): assert jobs[2]._subscribers[0].__code__ == nothing.__code__ assert jobs[2]._subscribers[1].__code__ == _Orchestrator._update_submission_status.__code__ assert jobs[2]._subscribers[2].__code__ == _Orchestrator._on_status_change.__code__ - mck.assert_called_once_with(jobs, timeout=5) + mck.assert_called_once_with(jobs, 5) def test_submit_sequence_development_mode(): @@ -475,7 +475,7 @@ def test_submit_sequence_with_callbacks_and_force_and_wait(): with mock.patch("taipy.core._orchestrator._orchestrator._Orchestrator._wait_until_job_finished") as mck: jobs = orchestrator.submit(scenario, callbacks=[nothing], force=True, wait=True, timeout=5).jobs - mck.assert_called_once_with(jobs, timeout=5) + mck.assert_called_once_with(jobs, 5) # jobs are created in a specific order and are correct assert len(jobs) == 4 diff --git a/tests/core/_orchestrator/test_orchestrator__submit_task.py b/tests/core/_orchestrator/test_orchestrator__submit_task.py index f8a019d4d4..af67d6655d 100644 --- a/tests/core/_orchestrator/test_orchestrator__submit_task.py +++ b/tests/core/_orchestrator/test_orchestrator__submit_task.py @@ -236,4 +236,4 @@ def test_submit_task_with_callbacks_and_force_and_wait(): assert job._subscribers[1].__code__ == _Orchestrator._update_submission_status.__code__ assert job._subscribers[2].__code__ == _Orchestrator._on_status_change.__code__ - mck.assert_called_once_with(job, timeout=2) + mck.assert_called_once_with(job, 2) From 3a18d68ef4da5b40b9198526d753c09a3d06f381 Mon Sep 17 00:00:00 2001 From: trgiangdo Date: Tue, 30 Jul 2024 14:53:48 +0700 Subject: [PATCH 2/2] fix: update break line on docstring --- taipy/core/_orchestrator/_orchestrator.py | 8 ++++---- taipy/core/scenario/scenario.py | 4 ++-- taipy/core/sequence/sequence.py | 4 ++-- taipy/core/taipy.py | 4 ++-- taipy/core/task/task.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/taipy/core/_orchestrator/_orchestrator.py b/taipy/core/_orchestrator/_orchestrator.py index d9fd92c00b..1eed8e9ddc 100644 --- a/taipy/core/_orchestrator/_orchestrator.py +++ b/taipy/core/_orchestrator/_orchestrator.py @@ -65,8 +65,8 @@ def submit( wait (bool): Wait for the orchestrated jobs created from the scenario or sequence submission to be finished in asynchronous mode. timeout (Union[float, int]): The optional maximum number of seconds to wait for the jobs to be finished - before returning. - If not provided and wait is True, the function waits indefinitely. + before returning.
+ If not provided and *wait* is True, the function waits indefinitely. **properties (dict[str, any]): A key worded variable length list of user additional arguments that will be stored within the `Submission^`. It can be accessed via `Submission.properties^`. Returns: @@ -120,8 +120,8 @@ def submit_task( wait (bool): Wait for the orchestrated job created from the task submission to be finished in asynchronous mode. timeout (Union[float, int]): The optional maximum number of seconds to wait for the job - to be finished before returning. - If not provided and wait is True, the function waits indefinitely. + to be finished before returning.
+ If not provided and *wait* is True, the function waits indefinitely. **properties (dict[str, any]): A key worded variable length list of user additional arguments that will be stored within the `Submission^`. It can be accessed via `Submission.properties^`. Returns: diff --git a/taipy/core/scenario/scenario.py b/taipy/core/scenario/scenario.py index 28c28d1743..4933f2b63d 100644 --- a/taipy/core/scenario/scenario.py +++ b/taipy/core/scenario/scenario.py @@ -608,8 +608,8 @@ def submit( wait (bool): Wait for the orchestrated jobs created from the scenario submission to be finished in asynchronous mode. timeout (Union[float, int]): The optional maximum number of seconds to wait for the jobs to be finished - before returning. - If not provided and wait is True, the function waits indefinitely. + before returning.
+ If not provided and *wait* is True, the function waits indefinitely. **properties (dict[str, any]): A keyworded variable length list of additional arguments. Returns: A `Submission^` containing the information of the submission. diff --git a/taipy/core/sequence/sequence.py b/taipy/core/sequence/sequence.py index 03b6c95717..698953b3c1 100644 --- a/taipy/core/sequence/sequence.py +++ b/taipy/core/sequence/sequence.py @@ -311,8 +311,8 @@ def submit( wait (bool): Wait for the orchestrated jobs created from the sequence submission to be finished in asynchronous mode. timeout (Union[float, int]): The maximum number of seconds to wait for the jobs to be finished before - returning. - If not provided and wait is True, the function waits indefinitely. + returning.
+ If not provided and *wait* is True, the function waits indefinitely. **properties (dict[str, any]): A keyworded variable length list of additional arguments. Returns: A `Submission^` containing the information of the submission. diff --git a/taipy/core/taipy.py b/taipy/core/taipy.py index 101787f25f..81ccaa0fa2 100644 --- a/taipy/core/taipy.py +++ b/taipy/core/taipy.py @@ -240,8 +240,8 @@ def submit( wait (bool): Wait for the orchestrated jobs created from the submission to be finished in asynchronous mode. timeout (Union[float, int]): The optional maximum number of seconds to wait - for the jobs to be finished before returning. - If not provided and wait is True, the function waits indefinitely. + for the jobs to be finished before returning.
+ If not provided and *wait* is True, the function waits indefinitely. **properties (dict[str, any]): A key-worded variable length list of user additional arguments that will be stored within the `Submission^`. It can be accessed via `Submission.properties^`. diff --git a/taipy/core/task/task.py b/taipy/core/task/task.py index 03bf3bf2a1..867c2dc461 100644 --- a/taipy/core/task/task.py +++ b/taipy/core/task/task.py @@ -231,8 +231,8 @@ def submit( wait (bool): Wait for the orchestrated job created from the task submission to be finished in asynchronous mode. timeout (Union[float, int]): The maximum number of seconds to wait for the job to be finished before - returning. - If not provided and wait is True, the function waits indefinitely. + returning.
+ If not provided and *wait* is True, the function waits indefinitely. **properties (dict[str, any]): A keyworded variable length list of additional arguments. Returns: A `Submission^` containing the information of the submission.