NRAO Home > CASA > CASA Cookbook and User Reference Manual
1.4.4.1 Monitoring Asynchronous Tasks
ALERT:
You should not use the go command to run a task asynchronously, as the “handle” will be swallowed by the Python task wrapper and you will not be able to access it with tm. This is also true if you run in a Python script.

There is a “taskmanager” tool tm that allows the user to retrieve the status of, and to abort the execution of, tasks running with async=True in the background. There are two methods of interest for the user, tm.retrieve and tm.abort.

If you run a task with async=True then several things will happen. First of all, the task returns a “handle” that is a number used to identify the process. This is printed to the screen, e.g.

CASA <5>: inp()  
#  mosaic :: Calculate a multi-field deconvolved image with selected clean algorithm:  
...  
async               =       True        #   if True run in the background, prompt is freed  
 
CASA <6>: mosaic()  
Connecting to controller:  (’127.0.0.1’, 60775)  
  Out[6]: 0

where the output value 0 is the handle id.

You can also catch the return value in a variable, e.g.

CASA <7>: handle = mosaic()  
...  
CASA <8>: print handle  
1

You should also see the usual messages from the task in the logger, with some extra lines of information

###############################################  
###  Begin Task: mosaic  ###  
Tue Oct 2 17:58:16 2007    NORMAL ::mosaic:  
""  
"Use: "  
tm.abort(return_value)    # to abort the asynchronous task  
tm.retrieve(return_value) # to retrieve the status  
""  
... usual messages here ...  
 
###  End Task: mosaic  ###  
###############################################  
""

for the example above.

To show the current status of an asynchronous task, use the tm.retrieve method using the handle id as the argument. For example,

CASA <9>: tm.retrieve(handle)  
  Out[9]: {’result’: None, ’status’: ’pending’}

or

CASA <10>: tm.retrieve(1)  
  Out[10]: {’result’: None, ’status’: ’pending’}

which means its still running. You should be seeing output in the logger also while the task is running.

When a task is finished, you will see:

CASA <11>: tm.retrieve(1)  
  Out[11]: {’result’: None, ’status’: ’done’}

which indicates completion.


More information about CASA may be found at the CASA web page

Copyright © 2010 Associated Universities Inc., Washington, D.C.

This code is available under the terms of the GNU General Public Lincense


Home | Contact Us | Directories | Site Map | Help | Privacy Policy | Search