CASA Process Management

CASA Process Management

Python developers can spawn processes at any time. These processes must be stopped when the user exits the CASA session. This page describes the process developers can use to create and register their processes for clean up when CASA exits. If processes are not stopped when the user exits CASA then these process that are left running can prevent CASA from exiting.


Gaining Access to the Process Manager

The CASA process manager can be access from the CASA state dictionary named 'casa'. This can be accessed from any module with:

from casa_system import procmgr

def some_func( ):


     print procmgr

The 'procmgr' object from the 'casa_system' module provides access to the process manager

Starting a Process

It is easy to start new processes using the process manager:


This will spawn a new process using the executable "/opt/local/bin/my-terrific-tool". It will start it with the arguments "arg1" and "arg2". The new process will be tracked within the process manager using the tag "terrific". Keep in mind that the tags provided must be unique.

Check on a Process

The process manager provides a 'running' function which allows for checking to see if a process is still running (or a tag is in use):


Stopping a Process

If you would like to stop a process, you must first fetch the container for the process:

myproc = procmgr.fetch("terrific")

and then use the container to stop the process:

myproc.stop( )

Restarting a Crashed Process

If a process starts but then crashes, the procmgr will return running()=True. Luckily, the process has an is_alive() method; in case of crash, running()=True but is_alive()=False:

procrun = procmgr.running("terrific") # True
myproc = procmgr.fetch("terrific")
if procrun and not myproc.is_alive(): # crash!
myproc.stop() # tell procmgr it stopped
procrun = False
except AttributeError: # fetch returns myproc=None if not created
if not procrun:
# start (or restart)
procmgr.create("terrific", ...) # as shown above