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 object j reaches the 'finished' state or fails. The 'finished' state occurs when all the job’s tasks are finished processing on the workers.

Note

Simulink® models cannot run while a MATLAB® session is blocked by wait. If you must run Simulink from the MATLAB client while also running jobs, do not use wait

example

wait(j,state) blocks execution in the client session until the specified job object changes state to the value of state. 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 run wait(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 specified state, or until timeout seconds elapse, whichever happens first. tf is false if timeout is exceeded before state is 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 a parallel.Job object.

Value of the job object’s State property 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 as true (1) or false (0).

If the job reaches state successfully, the function returns tf as true. If timeout is exceeded before state is reached, then tf is false.

Introduced in R2008a