3.11. Using Pre- and Post- exec commands

In some cases, tasks need customizable setup routines. A frequent example is the use of module load commands on various HPC platforms, which are used to prepare the runtime environment of the task’s executable in a well defined, system-specific way.

RP supports the invocation of such commands via the pre_exec and post_exec keys for the task description.


Pre- and Post- execution is performed on the resource headnode. Abusing these commands for any compute or I/O heavy load can lead to serious consequences, and will likely draw the wrath of the system administrators upon you! You have been warned…

The code example below shows the same environment setup we have been using in an earlier section, but now rendered via a pre_exec command:

cud = rp.TaskDescription()

cud.pre_exec    = ['export TEST=jabberwocky']
cud.executable  = '/bin/echo'
cud.arguments   = ['$RP_TASK_ID greets $TEST']

which again will make the environment variable TEST available during the execution of the task.

3.11.1. Running the Example

10_pre_and_post_exec.py. uses the code above to run a bag of echo commands:


The RP User-Guide concludes with this section. We recommend to check out the RP API documentation next and then move on to write your own RP application. You may find it useful to start from one of the examples of this guide, adding your own code as needed. If you find any issue, do not hesitate to open a ticket and we will be happy to offer our support.