Abstract base-class

class pylada.process.process.Process(maxtrials=1, **kwargs)[source]

Bases: object

Abstract base class of all processes.

This class defines the interface for processes. Derived classes should overload start(), poll(), and wait(). The first is called to actually launch the sub-process (for instance, an actual call to vasp in ProgramProcess). It receives a dictionary or Communicator instance with a description of how the process should be launched, eg the number of processors, nodes, and so forth. At this point, an external child program will generally be running. The second function, poll(), is called to check whether the sub-process, say VASP, is still running. It returns True if the process is finished. The last function is equivalent to calling poll() until it returns True.

Futhermore, a process can be terminated, killed and cleaned up. In general, a process is used as follows:

# initialized
process = SomeProcess()
# started on a number of processors
process.start(comm)
# checked 
try: 
  if process.poll():
    # finished, do something
except Fail as e:
  # error, do something
__init__(maxtrials=1, **kwargs)[source]

Initializes a process.

_cleanup()[source]

Cleans up behind process instance.

This may mean closing standard input/output file, removing temporary files.. By default, calls cleanup of process, and sets process to None.

done[source]

True if job already finished.

kill()[source]

Kills current process.

maxtrials = None

Maximum number of restarts.

nberrors = None

Number of times process was restarted.

Some derived instances may well restart a failed sub-process. This is how often it has been restarted.

nbrunning_processes[source]

Number of running processes.

For simple processes, this will be one or zero. For multitasking processes this may be something more.

poll()[source]

Polls current job.

Returns:True if the process is finished.
Raises NotStarted:
 If the process was never launched.
process = None

Currently running process.

This is the sub-process handled by this instance. At the lowest level, it is likely an instance of subprocess.Popen. It may, however, be a further abstraction, such as a ProgramProcess instance.

start(comm)[source]

Starts current job.

Parameters:

comm (Communicator) – Holds information about how to launch an mpi-aware process.

Returns:

True if process is already finished.

Raises:
  • MPISizeError – if no communicator is not None and comm[‘n’] == 0. Assumes that running on 0 processors is an error in resource allocation.
  • AlreadyStarted – When called for a second time. Each process should be unique: we do not want to run the VASP program twice in the same location, especially not simultaneously.
started = None

Whether the process was ever started.

Whether start() was called. It may only be called once.

terminate()[source]

Terminates current process.

wait()[source]

Waits for process to end, then cleanup.

Previous topic

Process Module

Next topic

Execution of an external program

This Page