Quellcode durchsuchen

Merge pull request #1604 from Avaiga/fix/#1602-wait-with-no-timeout-should-wait-indefinitely

Fix/#1602 - Wait with no timeout should wait indefinitely
Đỗ Trường Giang vor 10 Monaten
Ursprung
Commit
d087955529

+ 9 - 5
taipy/core/_orchestrator/_orchestrator.py

@@ -65,7 +65,8 @@ class _Orchestrator(_AbstractOrchestrator):
              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.
+                before returning.<br/>
+                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 @@ class _Orchestrator(_AbstractOrchestrator):
         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
@@ -119,7 +120,8 @@ class _Orchestrator(_AbstractOrchestrator):
              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.
+                to be finished before returning.<br/>
+                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 @@ class _Orchestrator(_AbstractOrchestrator):
             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 @@ class _Orchestrator(_AbstractOrchestrator):
             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()

+ 2 - 1
taipy/core/scenario/scenario.py

@@ -608,7 +608,8 @@ class Scenario(_Entity, Submittable, _Labeled):
             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.
+                before returning.<br/>
+                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.

+ 2 - 1
taipy/core/sequence/sequence.py

@@ -311,7 +311,8 @@ class Sequence(_Entity, Submittable, _Labeled):
             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.
+                returning.<br/>
+                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.

+ 2 - 1
taipy/core/taipy.py

@@ -240,7 +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.
+            for the jobs to be finished before returning.<br/>
+            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^`.
 

+ 2 - 1
taipy/core/task/task.py

@@ -231,7 +231,8 @@ class Task(_Entity, _Labeled):
             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.
+                returning.<br/>
+                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.

+ 2 - 2
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

+ 1 - 1
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)