Main Content

wait

Wait for job to change state

Description

example

wait(j)blocks execution in the client session until the job identified by the objectjreaches the'finished'state or fails. The'finished'state occurs when all the job’s tasks are finished processing on the workers.

Note

金宝app®models cannot run while a MATLAB®session is blocked bywait. If you must run Simulink from the MATLAB client while also running jobs, do not usewait

example

wait(j,state)blocks execution in the client session until the specified job object changes state to the value ofstate. Valid states to wait for are"queued","running", and"finished".

If the object is currently or was previously in the specified state, MATLAB does not wait and the function returns immediately. For example, if you runwait(j,"queued")for a job already in the"finished"state, the function returns immediately.

tf= wait(j,state,timeout)blocks execution until the job reaches the specifiedstate, or untiltimeoutseconds elapse, whichever happens first.tfisfalseiftimeoutis exceeded beforestateis reached.

Examples

collapse all

Submit a job to the queue, and wait for it to finish running before retrieving its results.

submit(j); wait(j,"running") diary(j)

Submit a batch job and wait for it to finish before retrieving its variables.

j = batch('myScript'); wait(j) load(j)

Input Arguments

collapse all

Job object whose change in state to wait for, specified as aparallel.Jobobject.

Value of the job object’sStateproperty to wait for, specified as one of the following:

  • "queued"

  • "running"

  • "finished"

Maximum time to wait in seconds, specified as a scalar integer.

Output Arguments

collapse all

True or false result, returned astrue(1) orfalse(0).

If the job reachesstatesuccessfully, the function returnstfastrue. Iftimeoutis exceeded beforestateis reached, thentfisfalse.

Introduced in R2008a