| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
from __future__ import print_function |
| 4 |
import drmaa |
| 5 |
import os |
| 6 |
|
| 7 |
|
| 8 |
def main(): |
| 9 |
"""Submit an array job, wait for them to finish, and collect results. |
| 10 |
This is slightly different from the example from sunsource because it only |
| 11 |
waits for the jobs that it submitted. |
| 12 |
""" |
| 13 |
s = drmaa.Session() |
| 14 |
s.initialize() |
| 15 |
print('Creating job template') |
| 16 |
jt = s.createJobTemplate() |
| 17 |
jt.remoteCommand = os.getcwd() + '/sleeper.sh' |
| 18 |
jt.args = ['42','Simon says:'] |
| 19 |
jt.joinFiles=True |
| 20 |
|
| 21 |
joblist = s.runBulkJobs(jt,1,30,2) |
| 22 |
print('Your job has been submitted with id ' + str(joblist)) |
| 23 |
|
| 24 |
s.synchronize(joblist, drmaa.Session.TIMEOUT_WAIT_FOREVER, False) |
| 25 |
for curjob in joblist: |
| 26 |
print('Collecting job ' + curjob) |
| 27 |
retval = s.wait(curjob, drmaa.Session.TIMEOUT_WAIT_FOREVER) |
| 28 |
print('Job: ' + str(retval.jobId) + ' finished with status ' + str(retval.hasExited)) |
| 29 |
|
| 30 |
print('Cleaning up') |
| 31 |
s.deleteJobTemplate(jt) |
| 32 |
s.exit() |
| 33 |
|
| 34 |
if __name__=='__main__': |
| 35 |
main() |