Skip to content

Commit 245cefa

Browse files
willfurnassdan-blanchard
authored andcommitted
Add cross-refs and captions to tutorial docs (#53)
1 parent 85dff13 commit 245cefa

1 file changed

Lines changed: 69 additions & 40 deletions

File tree

docs/tutorials.rst

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ also included in the repository.
1010
Starting and Stopping a Session
1111
-------------------------------
1212

13-
The following code segments (example1.py and example1.1.py) shows the most basic
14-
DRMAA python binding program.
13+
The following two code segments show the most basic DRMAA python binding
14+
program.
1515

1616
.. code-block:: python
1717
:linenos:
18+
:caption: example1.py
19+
:name: example-1
1820
1921
#!/usr/bin/env python
2022
@@ -55,6 +57,9 @@ function is called after ``exit()`` is called, it will return an error.
5557

5658
.. code-block:: python
5759
:linenos:
60+
:caption: example1.1.py
61+
:name: example-1-1
62+
:emphasize-lines: 13,15,18,19
5863
5964
#!/usr/bin/env python
6065
@@ -81,15 +86,15 @@ function is called after ``exit()`` is called, it will return an error.
8186
if __name__=='__main__':
8287
main()
8388
84-
This example is very similar to Example 1. The difference is that it uses the
85-
Grid Engine feature of reconnectable sessions. The DRMAA concept of a session is
86-
translated into a session tag in the Grid Engine job structure. That means that
87-
every job knows to which session it belongs. With reconnectable sessions, it's
88-
possible to initialize the DRMAA library to a previous session, allowing the
89-
library access to that session's job list. The only limitation, though, is that
90-
jobs which end between the calls to ``exit()`` and ``init()`` will be lost, as
91-
the reconnecting session will no longer see these jobs, and so won't know about
92-
them.
89+
This example is very similar to :ref:`Example 1 <example-1>`. The difference is
90+
that it uses the Grid Engine feature of reconnectable sessions. The DRMAA
91+
concept of a session is translated into a session tag in the Grid Engine job
92+
structure. That means that every job knows to which session it belongs. With
93+
reconnectable sessions, it's possible to initialize the DRMAA library to a
94+
previous session, allowing the library access to that session's job list. The
95+
only limitation, though, is that jobs which end between the calls to ``exit()``
96+
and ``init()`` will be lost, as the reconnecting session will no longer see
97+
these jobs, and so won't know about them.
9398

9499
On line 13, we use the contact attribute to get the contact information for this
95100
session. On line 15 we then exit the session. On line 18, we use the stored
@@ -101,18 +106,22 @@ the session a second time.
101106
Running a Job
102107
-------------
103108

104-
The following code segment (example2.py and example2.1.py) shows how to use the
105-
DRMAA python binding to submit a job to Grid Engine. It submits a small shell
106-
script (sleeper.sh) which takes two arguments:
109+
The following code segments show how to use the DRMAA python binding to
110+
submit a job to Grid Engine. It submits a small shell script (``sleeper.sh``)
111+
which takes two arguments:
107112

108113
.. code-block:: bash
114+
109115
#!/bin/bash
110116
echo "Hello world, the answer is $1"
111117
sleep 3s
112118
echo "$2 Bye world!"
113119
114120
.. code-block:: python
115121
:linenos:
122+
:caption: example2.py
123+
:name: example-2
124+
:emphasize-lines: 12-22
116125
117126
#!/usr/bin/env python
118127
@@ -169,6 +178,8 @@ If instead of a single job we had wanted to submit an array job, we could have
169178
replaced the else on line 18 and 19 with the following:
170179

171180
.. code-block:: python
181+
:caption: example2.1.py
182+
:name: example-2-1
172183
173184
jobid = s.runBulkJobs(jt, 1, 30, 2)
174185
print('Your jobs have been submitted with IDs %s' % jobid)
@@ -180,11 +191,14 @@ a list. On the last line, we print all the job ids.
180191
Waiting for a Job
181192
-----------------
182193

183-
Now we're going to extend our example to include waiting for a job to finish
184-
(example3.py, example3.1.py and example3.2.py).
194+
Now we're going to extend our example to include waiting for a job to finish.
195+
185196

186197
.. code-block:: python
187198
:linenos:
199+
:caption: example3.py
200+
:name: example-3
201+
:emphasize-lines: 21-22
188202
189203
#!/usr/bin/env python
190204
@@ -216,24 +230,27 @@ Now we're going to extend our example to include waiting for a job to finish
216230
main()
217231
218232
219-
This example is very similar to Example 2 except for line 21. On line 21 we call
220-
``wait()`` to wait for the job to end. We have to give ``wait()`` both the ID of
221-
the job for which we want to wait, and also how long we are willing to wait for
222-
the job to finish. This could be a number of seconds, or it could be either
223-
``TIMEOUT_WAIT_FOREVER`` or ``TIMEOUT_NO_WAIT``. ``wait()`` returns a
224-
``JobInfo`` tuple, which has the following attributes: ``jobId``, ``hasExited``,
225-
``hasSignal``, ``terminatedSignal``, ``hasCoreDump``, ``wasAborted``,
226-
``exitStatus``, and ``resourceUsage``. ``jobId`` is particularly useful if we
227-
passed in ``JOB_IDS_SESSION_ANY`` as the ID argument for ``wait()``, because
228-
without it we would have no way of knowing which job it actually waited for.
229-
Lastly, we print out the job ID and the exit status on line 22.
233+
This example is very similar to :ref:`Example 2 <example-2>` except for line
234+
21. On line 21 we call ``wait()`` to wait for the job to end. We have to give
235+
``wait()`` both the ID of the job for which we want to wait, and also how long
236+
we are willing to wait for the job to finish. This could be a number of
237+
seconds, or it could be either ``TIMEOUT_WAIT_FOREVER`` or ``TIMEOUT_NO_WAIT``.
238+
``wait()`` returns a ``JobInfo`` tuple, which has the following attributes:
239+
``jobId``, ``hasExited``, ``hasSignal``, ``terminatedSignal``, ``hasCoreDump``,
240+
``wasAborted``, ``exitStatus``, and ``resourceUsage``. ``jobId`` is
241+
particularly useful if we passed in ``JOB_IDS_SESSION_ANY`` as the ID argument
242+
for ``wait()``, because without it we would have no way of knowing which job it
243+
actually waited for. Lastly, we print out the job ID and the exit status on
244+
line 22.
230245

231246
An alternative to ``wait()`` when working with multiple jobs, such as jobs
232247
submitted by ``runBulkJobs()`` or multiple calls to ``runJob()`` is
233248
``synchronize()``. ``synchronize()`` waits for a set of jobs to finish. To use
234249
``synchronize()``, we could replace lines 18--22 with the following:
235250

236251
.. code-block:: python
252+
:caption: example3.1.py
253+
:name: example-3-1
237254
238255
joblist = s.runBulkJobs(jt, 1, 30, 2)
239256
print('Your jobs have been submitted with IDs %s' % joblist)
@@ -257,10 +274,12 @@ two functions is called for every job. Not doing so creates a memory leak. Note
257274
that calling ``synchronize()`` with dispose set to true flushes all accounting
258275
information for all jobs in the list. If you want to use ``synchronize()`` and
259276
still recover the accounting information, set ``dispose`` to ``False`` and call
260-
``wait()`` for each job. To do this in Example 3, we would replace lines 18--22
261-
with the following:
277+
``wait()`` for each job. To do this in :ref:`Example 3 <example-3>`, we would
278+
replace lines 18--22 with the following:
262279

263280
.. code-block:: python
281+
:caption: example3.2.py
282+
:name: example-3-2
264283
265284
joblist = s.runBulkJobs(jt, 1, 30, 2)
266285
print('Your jobs have been submitted with IDs %s' % joblist)
@@ -275,7 +294,7 @@ with the following:
275294
276295
What's different is that on line 21 we set ``dispose`` to ``False``, and then on
277296
lines 22--26 we wait once for each job, printing the exit status and usage
278-
information as we did in Example 3.
297+
information as we did in :ref:`Example 3 <example-3>`.
279298

280299
We pass ``joblist`` to ``synchronize()`` to wait for each job specifically.
281300
Otherwise, the ``wait()`` could end up waiting for a job submitted after the
@@ -284,10 +303,13 @@ call to ``synchronize()``.
284303
Controlling a Job
285304
-----------------
286305

287-
Now let's look at an example of how to control a job from DRMAA (example4.py):
306+
Now let's look at an example of how to control a job from DRMAA:
288307

289308
.. code-block:: python
290309
:linenos:
310+
:caption: example4.py
311+
:name: example-4
312+
:emphasize-lines: 20
291313
292314
#!/usr/bin/env python
293315
@@ -317,9 +339,10 @@ Now let's look at an example of how to control a job from DRMAA (example4.py):
317339
main()
318340
319341
320-
This example is very similar to Example 2 except for line 20. On line 20 we use
321-
``control()`` to delete the job we just submitted. Aside from deleting the job,
322-
we could have also used ``control()`` to suspend, resume, hold, or release it.
342+
This example is very similar to :ref:`Example 2 <example-2>` except for line
343+
20. On line 20 we use ``control()`` to delete the job we just submitted. Aside
344+
from deleting the job, we could have also used ``control()`` to suspend,
345+
resume, hold, or release it.
323346

324347
Note that ``control()`` can be used to control jobs not submitted through DRMAA.
325348
Any valid SGE job ID could be passed to ``control()`` as the ID of the job to
@@ -328,10 +351,13 @@ delete.
328351
Getting Job Status
329352
------------------
330353

331-
Here's an example of using DRMAA to query the status of a job (example5.py):
354+
Here's an example of using DRMAA to query the status of a job:
332355

333356
.. code-block:: python
334357
:linenos:
358+
:caption: example5.py
359+
:name: example-5
360+
:emphasize-lines: 22-40
335361
336362
#!/usr/bin/env python
337363
@@ -377,18 +403,21 @@ Here's an example of using DRMAA to query the status of a job (example5.py):
377403
if __name__=='__main__':
378404
main()
379405
380-
Again, this example is very similar to Example 2, this time with the exception
381-
of lines 22--40. On line 36, we use ``jobStatus()`` to get the status of the job.
382-
Line 43 determine what the job status is and report it.
406+
Again, this example is very similar to :ref:`Example 2 <example-2>`, this time
407+
with the exception of lines 22--40. On line 36, we use ``jobStatus()`` to get
408+
the status of the job. Line 43 determine what the job status is and report it.
383409

384410
Getting DRM information
385411
-----------------------
386412

387413
Lastly, let's look at how to query the DRMAA library for information about the
388-
DRMS and the DRMAA implementation itself (example6.py):
414+
DRMS and the DRMAA implementation itself:
389415

390416
.. code-block:: python
391417
:linenos:
418+
:caption: example6.py
419+
:name: example-6
420+
:emphasize-lines: 9-12
392421
393422
#!/usr/bin/env python
394423
@@ -413,4 +442,4 @@ that will be understood by this DRMAA instance. Normally on of these strings is
413442
used to select to which DRM this DRMAA instance should be bound. On line 10, we
414443
get the list of supported DRM systems. On line 11, we get the list of supported
415444
DRMAA implementations. On line 12, we get the version number of the DRMAA C
416-
binding specification supported by this DRMAA implementation.
445+
binding specification supported by this DRMAA implementation.

0 commit comments

Comments
 (0)