Debian Codegraph @

examples/example5.py

raw
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4 import drmaa
5 import time
6 import os
7
8
9 def main():
10 """Submit a job, and check its progress.
11 Note, need file called sleeper.sh in home directory.
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 jobid = s.runJob(jt)
22 print('Your job has been submitted with id ' + jobid)
23
24 # Who needs a case statement when you have dictionaries?
25 decodestatus = {
26 drmaa.JobState.UNDETERMINED: 'process status cannot be determined',
27 drmaa.JobState.QUEUED_ACTIVE: 'job is queued and active',
28 drmaa.JobState.SYSTEM_ON_HOLD: 'job is queued and in system hold',
29 drmaa.JobState.USER_ON_HOLD: 'job is queued and in user hold',
30 drmaa.JobState.USER_SYSTEM_ON_HOLD: 'job is queued and in user and system hold',
31 drmaa.JobState.RUNNING: 'job is running',
32 drmaa.JobState.SYSTEM_SUSPENDED: 'job is system suspended',
33 drmaa.JobState.USER_SUSPENDED: 'job is user suspended',
34 drmaa.JobState.DONE: 'job finished normally',
35 drmaa.JobState.FAILED: 'job finished, but failed',
36 }
37
38 for ix in range(10):
39 print('Checking ' + str(ix) + ' of 10 times')
40 print(decodestatus[s.jobStatus(jobid)])
41 time.sleep(5)
42
43 print('Cleaning up')
44 s.deleteJobTemplate(jt)
45 s.exit()
46
47 if __name__=='__main__':
48 main()