pax_global_header00006660000000000000000000000064133711070100014503gustar00rootroot0000000000000052 comment=ed6b926074d730f6fc37505360f65b8b79e8797f drmaa-python-0.7.9/000077500000000000000000000000001337110701000141235ustar00rootroot00000000000000drmaa-python-0.7.9/.coveragerc000066400000000000000000000002551337110701000162460ustar00rootroot00000000000000[run] source = drmaa omit = */python?.?/* */lib-python/?.?/*.py */lib_pypy/_*.py */site-packages/ordereddict.py */site-packages/nose/* */unittest2/* drmaa-python-0.7.9/.gitattributes000066400000000000000000000000161337110701000170130ustar00rootroot00000000000000* text=auto drmaa-python-0.7.9/.gitignore000066400000000000000000000005451337110701000161170ustar00rootroot00000000000000# Compiled python *.pyc *.pyo __pycache__ .DS_Store .coverage # C extensions *.so # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg lib lib64 # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox nosetests.xml # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject drmaa-python-0.7.9/.travis.yml000066400000000000000000000014141337110701000162340ustar00rootroot00000000000000os: linux dist: precise language: python python: - 2.7 - 3.4 - 3.5 - 3.6 - 3.7-dev sudo: required addons: hostname: drmaa.travis-ci.org hosts: - localhost - localhost.localdomain - drmaa.travis-ci.org notifications: email: false cache: pip # Install stuff before_install: - travis/install_sge.sh - export SGE_ROOT=/var/lib/gridengine - export SGE_CELL=default - export DRMAA_LIBRARY_PATH=/usr/lib/libdrmaa.so.1.0 - pip install --upgrade pip setuptools install: - pip install python-coveralls - pip install nose-cov - python setup.py install # Run test script: - nosetests -d -v --with-cov --cov drmaa --cov-config .coveragerc --logging-level=DEBUG # Calculate coverage after_success: - coveralls --config_file .coveragerc drmaa-python-0.7.9/MANIFEST.in000066400000000000000000000001611337110701000156570ustar00rootroot00000000000000include license.txt include *.rst recursive-include examples * recursive-include test * recursive-include docs * drmaa-python-0.7.9/README.rst000066400000000000000000000046701337110701000156210ustar00rootroot00000000000000DRMAA Python ------------ .. image:: https://img.shields.io/travis/pygridtools/drmaa-python/stable.svg :alt: Build status :target: https://travis-ci.org/pygridtools/drmaa-python .. image:: https://img.shields.io/coveralls/pygridtools/drmaa-python/stable.svg :target: https://coveralls.io/r/pygridtools/drmaa-python .. image:: https://img.shields.io/pypi/dm/drmaa.svg :target: https://warehouse.python.org/project/drmaa/ :alt: PyPI downloads .. image:: https://img.shields.io/pypi/v/drmaa.svg :target: https://warehouse.python.org/project/drmaa/ :alt: Latest version on PyPI .. image:: https://img.shields.io/pypi/l/drmaa.svg :alt: License `Distributed Resource Management Application API `__ (DRMAA) bindings for Python. For more information `read the docs `__. If you simply want to run Python functions on a DRMAA-compatible grid, use `GridMap `__. Requirements ~~~~~~~~~~~~ - Python 2.7+ - A DRMAA-compatible cluster (e.g., Grid Engine) Installation ~~~~~~~~~~~~ To use the DRMAA Python library, you need to install it via ``pip``: .. code-block:: bash pip install drmaa and then setup any environment variables that are necessary for your particular DRM system. For SGE, this means ``SGE_ROOT`` and ``SGE_CELL``, which should be set as follows: .. code-block:: bash export SGE_ROOT=/path/to/gridengine export SGE_CELL=default where ``/path/to/gridengine/`` is replaced with the actual path to your Grid Engine installation, and ``default`` is replaced with your installation's actual cell. The path is typically ``/var/lib/gridengine``. You will also need access to the ``libdrmaa.so.1.0`` C library, which can often be installed as part of the ``libdrmaa-dev`` package on most Unixes. Once you have installed that, you may need to tell DRMAA Python where it is installed by setting the ``DRMAA_LIBRARY_PATH`` environment variable, if it is not installed in a location that Python usually looks for libraries. .. code-block:: bash export DRMAA_LIBRARY_PATH=/usr/lib/libdrmaa.so.1.0 Acknowledgments ~~~~~~~~~~~~~~~ Thank you to `StatPro `__ and `Educational Testing Service `__ for funding the development of DRMAA Python. Changelog ~~~~~~~~~ `See GitHub releases `__. drmaa-python-0.7.9/docs/000077500000000000000000000000001337110701000150535ustar00rootroot00000000000000drmaa-python-0.7.9/docs/Makefile000066400000000000000000000127201337110701000165150ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/DRMAAPython.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/DRMAAPython.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/DRMAAPython" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/DRMAAPython" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." drmaa-python-0.7.9/docs/conf.py000066400000000000000000000207611337110701000163600ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # DRMAA Python documentation build configuration file, created by # sphinx-quickstart on Wed Nov 27 13:52:19 2013. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import os import sys # Handle modules that will not import properly because they rely on C class Mock(object): def __init__(self, *args, **kwargs): pass def __call__(self, *args, **kwargs): return Mock() @classmethod def __getattr__(cls, name): if name in ('__file__', '__path__'): return '/dev/null' elif name[0] == name[0].upper(): mockType = type(name, (), {}) mockType.__module__ = __name__ return mockType else: return Mock() MOCK_MODULES = ['drmaa.wrappers'] for mod_name in MOCK_MODULES: sys.modules[mod_name] = Mock() # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('..')) import drmaa # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.mathjax', 'sphinx.ext.viewcode'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'DRMAA Python' copyright = u'2013, Dan Blanchard, David Ressman, Enrico Sirola' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = drmaa.__version__ # The full version, including alpha/beta/rc tags. release = drmaa.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". # html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'DRMAAPythondoc' # -- Options for LaTeX output -------------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'DRMAAPython.tex', u'DRMAA Python Documentation', u'Dan Blanchard, David Ressman, Enrico Sirola', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'drmaapython', u'DRMAA Python Documentation', [u'Dan Blanchard, David Ressman, Enrico Sirola'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'DRMAAPython', u'DRMAA Python Documentation', u'Dan Blanchard, David Ressman, Enrico Sirola', 'DRMAAPython', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' drmaa-python-0.7.9/docs/drmaa.rst000066400000000000000000000001711337110701000166700ustar00rootroot00000000000000:mod:`drmaa` Package ---------------------- .. automodule:: drmaa :members: :undoc-members: :show-inheritance: drmaa-python-0.7.9/docs/index.rst000066400000000000000000000007211337110701000167140ustar00rootroot00000000000000.. DRMAA Python documentation master file, created by sphinx-quickstart on Wed Nov 27 13:52:19 2013. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to DRMAA Python's documentation! ======================================== Contents: .. toctree:: :maxdepth: 2 tutorials drmaa Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` drmaa-python-0.7.9/docs/make.bat000066400000000000000000000117621337110701000164670ustar00rootroot00000000000000@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\DRMAAPython.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\DRMAAPython.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) :end drmaa-python-0.7.9/docs/tutorials.rst000066400000000000000000000410311337110701000176320ustar00rootroot00000000000000Distributed Resource Management Application API =============================================== This guide is a tutorial for getting started programming with DRMAA. It is basically a one to one translation of the original in C for Grid Engine. It assumes that you already know what DRMAA is and that you have drmaa-python installed. If not, have a look at Installing. The following code segments are also included in the repository. Starting and Stopping a Session ------------------------------- The following two code segments show the most basic DRMAA python binding program. .. code-block:: python :linenos: :caption: example1.py :name: example-1 #!/usr/bin/env python import drmaa def main(): """Create a drmaa session and exit""" with drmaa.Session() as s: print('A session was started successfully') if __name__=='__main__': main() The first thing to notice is that every call to a DRMAA function will return an error code. In this tutorial, we ignore all error codes. Now let's look at the functions being called. First, on line 7, we initialise a ``Session`` object by calling ``drmaa.Session()``. The ``Session`` is automatically initialized via ``initialize()``, and it creates a session and starts an event client listener thread. The session is used for organizing jobs submitted through DRMAA, and the thread is used to receive updates from the queue master about the state of jobs and the system in general. Once ``initialize()`` has been called successfully, it is the responsibility of the calling application to also call ``exit()`` before terminating, but since we're using it as a context manager via the ``with`` statement, that will happene automatically. If an application does not call ``exit()`` before terminating, session state may be left behind in the user's home directory, and the queue master may be left with a dead event client handle, which can decrease queue master performance. At the end of our program, ``exit()`` is called automatically when we leave the ``with`` block. ``exit()`` cleans up the session and stops the event client listener thread. Most other DRMAA functions must be called before ``exit()``. Some functions, like ``getContact()``, can be called after ``exit()``, but these functions only provide general information. Any function that does work, such as ``runJob()`` or ``wait()`` must be called before ``exit()`` is called. If such a function is called after ``exit()`` is called, it will return an error. .. code-block:: python :linenos: :caption: example1.1.py :name: example-1-1 :emphasize-lines: 13,15,18,19 #!/usr/bin/env python import drmaa def main(): """ Create a session, show that each session has an ID, use session ID to disconnect, then reconnect. Finally, exit. """ s = drmaa.Session() s.initialize() print('A session was started successfully') response = s.contact print('session contact returns: %s' % response) s.exit() print('Exited from session') s.initialize(response) print('Session was restarted successfullly') s.exit() if __name__=='__main__': main() This example is very similar to :ref:`Example 1 `. The difference is that it uses the Grid Engine feature of reconnectable sessions. The DRMAA concept of a session is translated into a session tag in the Grid Engine job structure. That means that every job knows to which session it belongs. With reconnectable sessions, it's possible to initialize the DRMAA library to a previous session, allowing the library access to that session's job list. The only limitation, though, is that jobs which end between the calls to ``exit()`` and ``init()`` will be lost, as the reconnecting session will no longer see these jobs, and so won't know about them. On line 13, we use the contact attribute to get the contact information for this session. On line 15 we then exit the session. On line 18, we use the stored contact information to reconnect to the previous session. Had we submitted jobs before calling ``exit()``, those jobs would now be available again for operations such as ``wait()`` and ``synchronize()``. Finally, on line 19 we exit the session a second time. Running a Job ------------- The following code segments show how to use the DRMAA python binding to submit a job to Grid Engine. It submits a small shell script (``sleeper.sh``) which takes two arguments: .. code-block:: bash #!/bin/bash echo "Hello world, the answer is $1" sleep 3s echo "$2 Bye world!" .. code-block:: python :linenos: :caption: example2.py :name: example-2 :emphasize-lines: 12-22 #!/usr/bin/env python import drmaa import os def main(): """ Submit a job. Note, need file called sleeper.sh in current directory. """ with drmaa.Session() as s: print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.path.join(os.getcwd(), 'sleeper.sh') jt.args = ['42', 'Simon says:'] jt.joinFiles=True jobid = s.runJob(jt) print('Your job has been submitted with ID %s' % jobid) print('Cleaning up') s.deleteJobTemplate(jt) if __name__=='__main__': main() The beginning and end of this program are the same as the first example. What's new is in lines 12--22. On line 12 we ask DRMAA to allocate a job template for us. A job template is a structure used to store information about a job to be submitted. The same template can be reused for multiple calls to ``runJob()`` or ``runBulkJob()``. On line 13 we set the ``remoteCommand`` attribute. This attribute tells DRMAA where to find the program we want to run. Its value is the path to the executable. The path can be either relative or absolute. If relative, it is relative to the ``workingDirectory`` attribute, which if not set defaults to the user's home directory. For more information on DRMAA attributes, please see the attributes man page. Note that for this program to work, the script ``sleeper.sh`` must be in the current directory. On line 14 we set the ``args`` attribute. This attribute tells DRMAA what arguments to pass to the executable. On line 17 we submit the job with ``runJob()``. DRMAA will place the ID assigned to the job into the character array we passed to ``runJob()``. The job is now running as though submitted by ``qsub`` or ``bsub``. At this point calling ``exit()`` and/or terminating the program will have no effect on the job. To clean things up, we delete the job template on line 21. This frees the memory DRMAA set aside for the job template, but has no effect on submitted jobs. If instead of a single job we had wanted to submit an array job, we could have replaced the else on line 18 and 19 with the following: .. code-block:: python :caption: example2.1.py :name: example-2-1 jobid = s.runBulkJobs(jt, 1, 30, 2) print('Your jobs have been submitted with IDs %s' % jobid) This code segment submits an array job with 15 tasks numbered 1, 3, 5, 7, etc. An important difference to note is that ``runBulkJobs()`` returns the job ids in a list. On the last line, we print all the job ids. Waiting for a Job ----------------- Now we're going to extend our example to include waiting for a job to finish. .. code-block:: python :linenos: :caption: example3.py :name: example-3 :emphasize-lines: 21-22 #!/usr/bin/env python import drmaa import os def main(): """ Submit a job and wait for it to finish. Note, need file called sleeper.sh in home directory. """ with drmaa.Session() as s: print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.path.join(os.getcwd(), 'sleeper.sh') jt.args = ['42', 'Simon says:'] jt.joinFiles = True jobid = s.runJob(jt) print('Your job has been submitted with ID %s' % jobid) retval = s.wait(jobid, drmaa.Session.TIMEOUT_WAIT_FOREVER) print('Job: {0} finished with status {1}'.format(retval.jobId, retval.hasExited)) print('Cleaning up') s.deleteJobTemplate(jt) if __name__=='__main__': main() This example is very similar to :ref:`Example 2 ` except for line 21. On line 21 we call ``wait()`` to wait for the job to end. We have to give ``wait()`` both the ID of the job for which we want to wait, and also how long we are willing to wait for the job to finish. This could be a number of seconds, or it could be either ``TIMEOUT_WAIT_FOREVER`` or ``TIMEOUT_NO_WAIT``. ``wait()`` returns a ``JobInfo`` tuple, which has the following attributes: ``jobId``, ``hasExited``, ``hasSignal``, ``terminatedSignal``, ``hasCoreDump``, ``wasAborted``, ``exitStatus``, and ``resourceUsage``. ``jobId`` is particularly useful if we passed in ``JOB_IDS_SESSION_ANY`` as the ID argument for ``wait()``, because without it we would have no way of knowing which job it actually waited for. Lastly, we print out the job ID and the exit status on line 22. An alternative to ``wait()`` when working with multiple jobs, such as jobs submitted by ``runBulkJobs()`` or multiple calls to ``runJob()`` is ``synchronize()``. ``synchronize()`` waits for a set of jobs to finish. To use ``synchronize()``, we could replace lines 18--22 with the following: .. code-block:: python :caption: example3.1.py :name: example-3-1 joblist = s.runBulkJobs(jt, 1, 30, 2) print('Your jobs have been submitted with IDs %s' % joblist) s.synchronize(joblist, drmaa.Session.TIMEOUT_WAIT_FOREVER, True) With the switch to ``runBulkJobs()`` we now have several jobs for which to wait. On line 20, instead of calling ``wait()``, we call ``synchronize()``. ``synchronize()`` takes only three interesting parameters. The first is the list of string IDs for which to wait. If the special ID, ``JOB_IDS_SESSION_ALL``, appears in the array, ``synchronize()`` will wait for all jobs submitted via DRMAA during this session (i.e., since ``initialize()`` was called). The second is how long to wait for all the jobs in the list to finish. This is the same as the timeout parameter for ``wait()``. The third is whether this call to ``synchronize()`` should clean up after the job. After a job completes, it leaves behind accounting information, such as exit status and usage, until either ``wait()`` or ``synchronize()`` with ``dispose`` set to ``True`` is called. It is the responsibility of the application to make sure one of these two functions is called for every job. Not doing so creates a memory leak. Note that calling ``synchronize()`` with dispose set to true flushes all accounting information for all jobs in the list. If you want to use ``synchronize()`` and still recover the accounting information, set ``dispose`` to ``False`` and call ``wait()`` for each job. To do this in :ref:`Example 3 `, we would replace lines 18--22 with the following: .. code-block:: python :caption: example3.2.py :name: example-3-2 joblist = s.runBulkJobs(jt, 1, 30, 2) print('Your jobs have been submitted with IDs %s' % joblist) s.synchronize(joblist, drmaa.Session.TIMEOUT_WAIT_FOREVER, False) for curjob in joblist: print('Collecting job ' + curjob) retval = s.wait(curjob, drmaa.Session.TIMEOUT_WAIT_FOREVER) print('Job: {0} finished with status {1}'.format(retval.jobId, retval.hasExited)) What's different is that on line 21 we set ``dispose`` to ``False``, and then on lines 22--26 we wait once for each job, printing the exit status and usage information as we did in :ref:`Example 3 `. We pass ``joblist`` to ``synchronize()`` to wait for each job specifically. Otherwise, the ``wait()`` could end up waiting for a job submitted after the call to ``synchronize()``. Controlling a Job ----------------- Now let's look at an example of how to control a job from DRMAA: .. code-block:: python :linenos: :caption: example4.py :name: example-4 :emphasize-lines: 20 #!/usr/bin/env python import drmaa import os def main(): """Submit a job, then kill it. Note, need file called sleeper.sh in home directory. """ with drmaa.Session() as s: print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.path.join(os.getcwd(), 'sleeper.sh') jt.args = ['42', 'Simon says:'] jt.joinFiles = True jobid = s.runJob(jt) print('Your job has been submitted with ID %s' % jobid) # options are: SUSPEND, RESUME, HOLD, RELEASE, TERMINATE s.control(jobid, drmaa.JobControlAction.TERMINATE) print('Cleaning up') s.deleteJobTemplate(jt) if __name__=='__main__': main() This example is very similar to :ref:`Example 2 ` except for line 20. On line 20 we use ``control()`` to delete the job we just submitted. Aside from deleting the job, we could have also used ``control()`` to suspend, resume, hold, or release it. Note that ``control()`` can be used to control jobs not submitted through DRMAA. Any valid SGE job ID could be passed to ``control()`` as the ID of the job to delete. Getting Job Status ------------------ Here's an example of using DRMAA to query the status of a job: .. code-block:: python :linenos: :caption: example5.py :name: example-5 :emphasize-lines: 22-40 #!/usr/bin/env python import drmaa import time import os def main(): """ Submit a job, and check its progress. Note, need file called sleeper.sh in home directory. """ with drmaa.Session() as s: print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.path.join(os.getcwd(), 'sleeper.sh') jt.args = ['42', 'Simon says:'] jt.joinFiles=True jobid = s.runJob(jt) print('Your job has been submitted with ID %s' % jobid) # Who needs a case statement when you have dictionaries? decodestatus = {drmaa.JobState.UNDETERMINED: 'process status cannot be determined', drmaa.JobState.QUEUED_ACTIVE: 'job is queued and active', drmaa.JobState.SYSTEM_ON_HOLD: 'job is queued and in system hold', drmaa.JobState.USER_ON_HOLD: 'job is queued and in user hold', drmaa.JobState.USER_SYSTEM_ON_HOLD: 'job is queued and in user and system hold', drmaa.JobState.RUNNING: 'job is running', drmaa.JobState.SYSTEM_SUSPENDED: 'job is system suspended', drmaa.JobState.USER_SUSPENDED: 'job is user suspended', drmaa.JobState.DONE: 'job finished normally', drmaa.JobState.FAILED: 'job finished, but failed'} for ix in range(10): print('Checking %s of 10 times' % ix) print decodestatus(s.jobStatus(jobid)) time.sleep(5) print('Cleaning up') s.deleteJobTemplate(jt) if __name__=='__main__': main() Again, this example is very similar to :ref:`Example 2 `, this time with the exception of lines 22--40. On line 36, we use ``jobStatus()`` to get the status of the job. Line 43 determine what the job status is and report it. Getting DRM information ----------------------- Lastly, let's look at how to query the DRMAA library for information about the DRMS and the DRMAA implementation itself: .. code-block:: python :linenos: :caption: example6.py :name: example-6 :emphasize-lines: 9-12 #!/usr/bin/env python import drmaa def main(): """ Query the system. """ with drmaa.Session() as s: print('A DRMAA object was created') print('Supported contact strings: %s' % s.contact) print('Supported DRM systems: %s' % s.drmsInfo) print('Supported DRMAA implementations: %s' % s.drmaaImplementation) print('Version %s' % s.version) print('Exiting') if __name__=='__main__': main() On line 9, we get the contact string list. This is the list of contact strings that will be understood by this DRMAA instance. Normally on of these strings is used to select to which DRM this DRMAA instance should be bound. On line 10, we get the list of supported DRM systems. On line 11, we get the list of supported DRMAA implementations. On line 12, we get the version number of the DRMAA C binding specification supported by this DRMAA implementation. drmaa-python-0.7.9/drmaa/000077500000000000000000000000001337110701000152075ustar00rootroot00000000000000drmaa-python-0.7.9/drmaa/__init__.py000066400000000000000000000123121337110701000173170ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2008 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- # # Author: Enrico Sirola """ A python package for DRM job submission and control. This package is an implementation of the DRMAA 1.0 Python language binding specification (http://www.ogf.org/documents/GFD.143.pdf). The source is hosted on GitHub: https://github.com/pygridtools/drmaa-python Releases are available from PyPi: https://pypi.python.org/pypi/drmaa Documentation is hosted on ReadTheDocs: http://drmaa-python.readthedocs.org/ :author: Enrico Sirola (enrico.sirola@statpro.com) :author: Dan Blanchard (dan.blanchard@gmail.com) """ from __future__ import absolute_import, print_function, unicode_literals from .const import (ATTR_BUFFER, BLOCK_EMAIL, CONTACT_BUFFER, control_action_to_string, DEADLINE_TIME, DRM_SYSTEM_BUFFER, DRMAA_IMPLEMENTATION_BUFFER, DURATION_HLIMIT, DURATION_SLIMIT, ERROR_PATH, ERROR_STRING_BUFFER, INPUT_PATH, JOB_CATEGORY, JOB_IDS_SESSION_ALL, JOB_IDS_SESSION_ANY, JOB_NAME, job_state, JobControlAction, JOBNAME_BUFFER, JobState, JobSubmissionState, JOIN_FILES, JS_STATE, NATIVE_SPECIFICATION, NO_MORE_ELEMENTS, OUTPUT_PATH, PLACEHOLDER_HD, PLACEHOLDER_INCR, PLACEHOLDER_WD, REMOTE_COMMAND, SIGNAL_BUFFER, START_TIME, status_to_string, string_to_control_action, submission_state, SUBMISSION_STATE_ACTIVE, SUBMISSION_STATE_HOLD, TIMEOUT_NO_WAIT, TIMEOUT_WAIT_FOREVER, TRANSFER_FILES, V_ARGV, V_EMAIL, V_ENV, WCT_HLIMIT, WCT_SLIMIT, WD) from .errors import (AlreadyActiveSessionException, AuthorizationException, ConflictingAttributeValuesException, DefaultContactStringException, DeniedByDrmException, DrmCommunicationException, DrmsExitException, DrmsInitException, ExitTimeoutException, HoldInconsistentStateException, IllegalStateException, InternalException, InvalidAttributeFormatException, InvalidContactStringException, InvalidJobException, InvalidJobTemplateException, NoActiveSessionException, NoDefaultContactStringSelectedException, ReleaseInconsistentStateException, ResumeInconsistentStateException, SuspendInconsistentStateException, TryLaterException, UnsupportedAttributeException, InvalidArgumentException, InvalidAttributeValueException, OutOfMemoryException) from .session import JobInfo, JobTemplate, Session from .version import __version__, VERSION __docformat__ = "restructuredtext en" __all__ = ['JobInfo', 'JobTemplate', 'Session', 'AlreadyActiveSessionException', 'AuthorizationException', 'ConflictingAttributeValuesException', 'DefaultContactStringException', 'DeniedByDrmException', 'DrmCommunicationException', 'DrmsExitException', 'DrmsInitException', 'ExitTimeoutException', 'HoldInconsistentStateException', 'IllegalStateException', 'InternalException', 'InvalidAttributeFormatException', 'InvalidContactStringException', 'InvalidJobException', 'InvalidJobTemplateException', 'NoActiveSessionException', 'NoDefaultContactStringSelectedException', 'ReleaseInconsistentStateException', 'ResumeInconsistentStateException', 'SuspendInconsistentStateException', 'TryLaterException', 'UnsupportedAttributeException', 'InvalidArgumentException', 'InvalidAttributeValueException', 'OutOfMemoryException', 'ATTR_BUFFER', 'BLOCK_EMAIL', 'CONTACT_BUFFER', 'control_action_to_string', 'DEADLINE_TIME', 'DRM_SYSTEM_BUFFER', 'DRMAA_IMPLEMENTATION_BUFFER', 'DURATION_HLIMIT', 'DURATION_SLIMIT', 'ERROR_PATH', 'ERROR_STRING_BUFFER', 'INPUT_PATH', 'JOB_CATEGORY', 'JOB_IDS_SESSION_ALL', 'JOB_IDS_SESSION_ANY', 'JOB_NAME', 'job_state', 'JobControlAction', 'JOBNAME_BUFFER', 'JobState', 'JobSubmissionState', 'JOIN_FILES', 'JS_STATE', 'NATIVE_SPECIFICATION', 'NO_MORE_ELEMENTS', 'OUTPUT_PATH', 'PLACEHOLDER_HD', 'PLACEHOLDER_INCR', 'PLACEHOLDER_WD', 'REMOTE_COMMAND', 'SIGNAL_BUFFER', 'START_TIME', 'status_to_string', 'string_to_control_action', 'submission_state', 'SUBMISSION_STATE_ACTIVE', 'SUBMISSION_STATE_HOLD', 'TIMEOUT_NO_WAIT', 'TIMEOUT_WAIT_FOREVER', 'TRANSFER_FILES', 'V_ARGV', 'V_EMAIL', 'V_ENV', 'WCT_HLIMIT', 'WCT_SLIMIT', 'WD'] drmaa-python-0.7.9/drmaa/const.py000066400000000000000000000101061337110701000167050ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2009 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # email: info@riskmap.net # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- # # Author: Enrico Sirola # """ drmaa constants """ from __future__ import absolute_import, print_function, unicode_literals import locale # Encoding to use for passing strings to C library ENCODING = locale.getpreferredencoding() # drmaa_get_attribute() ATTR_BUFFER = 1024 # drmaa_get_contact() CONTACT_BUFFER = 1024 # drmaa_get_DRM_system() DRM_SYSTEM_BUFFER = 1024 # drmaa_get_DRM_system() DRMAA_IMPLEMENTATION_BUFFER = 1024 # Agreed buffer length constants # these are recommended minimum values ERROR_STRING_BUFFER = 1024 JOBNAME_BUFFER = 1024 SIGNAL_BUFFER = 32 # Agreed constants TIMEOUT_WAIT_FOREVER = -1 TIMEOUT_NO_WAIT = 0 JOB_IDS_SESSION_ANY = b"DRMAA_JOB_IDS_SESSION_ANY" JOB_IDS_SESSION_ALL = b"DRMAA_JOB_IDS_SESSION_ALL" SUBMISSION_STATE_ACTIVE = "drmaa_active" SUBMISSION_STATE_HOLD = "drmaa_hold" # Agreed placeholder names PLACEHOLDER_INCR = b"$drmaa_incr_ph$" PLACEHOLDER_HD = b"$drmaa_hd_ph$" PLACEHOLDER_WD = b"$drmaa_wd_ph$" # Agreed names of job template attributes REMOTE_COMMAND = b"drmaa_remote_command" JS_STATE = b"drmaa_js_state" WD = b"drmaa_wd" JOB_CATEGORY = b"drmaa_job_category" NATIVE_SPECIFICATION = b"drmaa_native_specification" BLOCK_EMAIL = b"drmaa_block_email" START_TIME = b"drmaa_start_time" JOB_NAME = b"drmaa_job_name" INPUT_PATH = b"drmaa_input_path" OUTPUT_PATH = b"drmaa_output_path" ERROR_PATH = b"drmaa_error_path" JOIN_FILES = b"drmaa_join_files" TRANSFER_FILES = b"drmaa_transfer_files" DEADLINE_TIME = b"drmaa_deadline_time" WCT_HLIMIT = b"drmaa_wct_hlimit" WCT_SLIMIT = b"drmaa_wct_slimit" DURATION_HLIMIT = b"drmaa_duration_hlimit" DURATION_SLIMIT = b"drmaa_duration_slimit" # names of job template vector attributes V_ARGV = b"drmaa_v_argv" V_ENV = b"drmaa_v_env" V_EMAIL = b"drmaa_v_email" NO_MORE_ELEMENTS = 25 def job_state(code): return _JOB_PS[code] class JobState(object): UNDETERMINED = 'undetermined' QUEUED_ACTIVE = 'queued_active' SYSTEM_ON_HOLD = 'system_on_hold' USER_ON_HOLD = 'user_on_hold' USER_SYSTEM_ON_HOLD = 'user_system_on_hold' RUNNING = 'running' SYSTEM_SUSPENDED = 'system_suspended' USER_SUSPENDED = 'user_suspended' USER_SYSTEM_SUSPENDED = 'user_system_suspended' DONE = 'done' FAILED = 'failed' # Job control action class JobControlAction(object): SUSPEND = 'suspend' RESUME = 'resume' HOLD = 'hold' RELEASE = 'release' TERMINATE = 'terminate' _JOB_CONTROL = [JobControlAction.SUSPEND, JobControlAction.RESUME, JobControlAction.HOLD, JobControlAction.RELEASE, JobControlAction.TERMINATE] def string_to_control_action(operation): return _JOB_CONTROL.index(operation) def control_action_to_string(code): return _JOB_CONTROL[code] def status_to_string(status): return _JOB_PS[status] _JOB_PS = {0x00: JobState.UNDETERMINED, 0x10: JobState.QUEUED_ACTIVE, 0x11: JobState.SYSTEM_ON_HOLD, 0x12: JobState.USER_ON_HOLD, 0x13: JobState.USER_SYSTEM_ON_HOLD, 0x20: JobState.RUNNING, 0x21: JobState.SYSTEM_SUSPENDED, 0x22: JobState.USER_SUSPENDED, 0x23: JobState.USER_SYSTEM_SUSPENDED, 0x30: JobState.DONE, 0x40: JobState.FAILED} # State at submission time class JobSubmissionState(object): HOLD_STATE = SUBMISSION_STATE_HOLD ACTIVE_STATE = SUBMISSION_STATE_ACTIVE _SUBMISSION_STATE = [JobSubmissionState.HOLD_STATE, JobSubmissionState.ACTIVE_STATE] def submission_state(code): return _SUBMISSION_STATE[code] drmaa-python-0.7.9/drmaa/errors.py000066400000000000000000000073411337110701000171020ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2009 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # email: info@riskmap.net # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- # # Author: Enrico Sirola """ drmaa errors """ from ctypes import create_string_buffer from drmaa.const import ERROR_STRING_BUFFER class DrmaaException(Exception): """ A common ancestor to all DRMAA Error classes. """ pass class AlreadyActiveSessionException(DrmaaException): pass class AuthorizationException(DrmaaException): pass class ConflictingAttributeValuesException(DrmaaException, AttributeError): pass class DefaultContactStringException(DrmaaException): pass class DeniedByDrmException(DrmaaException): pass class DrmCommunicationException(DrmaaException): pass class DrmsExitException(DrmaaException): pass class DrmsInitException(DrmaaException): pass class ExitTimeoutException(DrmaaException): pass class HoldInconsistentStateException(DrmaaException): pass class IllegalStateException(DrmaaException): pass class InternalException(DrmaaException): pass class InvalidAttributeFormatException(DrmaaException, AttributeError): pass class InvalidContactStringException(DrmaaException): pass class InvalidJobException(DrmaaException): pass class InvalidJobTemplateException(DrmaaException): pass class NoActiveSessionException(DrmaaException): pass class NoDefaultContactStringSelectedException(DrmaaException): pass class ReleaseInconsistentStateException(DrmaaException): pass class ResumeInconsistentStateException(DrmaaException): pass class SuspendInconsistentStateException(DrmaaException): pass class TryLaterException(DrmaaException): pass class UnsupportedAttributeException(DrmaaException, AttributeError): pass class InvalidArgumentException(DrmaaException, AttributeError): pass class InvalidAttributeValueException(DrmaaException, AttributeError): pass class OutOfMemoryException(DrmaaException, MemoryError): pass error_buffer = create_string_buffer(ERROR_STRING_BUFFER) def error_check(code): if code == 0: return else: error_string = "code {0}: {1}".format(code, error_buffer.value.decode()) try: raise _ERRORS[code - 1](error_string) except IndexError: raise DrmaaException(error_string) # da vedere: NO_RUSAGE, NO_MORE_ELEMENTS _ERRORS = [InternalException, DrmCommunicationException, AuthorizationException, InvalidArgumentException, NoActiveSessionException, OutOfMemoryException, InvalidContactStringException, DefaultContactStringException, NoDefaultContactStringSelectedException, DrmsInitException, AlreadyActiveSessionException, DrmsExitException, InvalidAttributeFormatException, InvalidAttributeValueException, ConflictingAttributeValuesException, TryLaterException, DeniedByDrmException, InvalidJobException, ResumeInconsistentStateException, SuspendInconsistentStateException, HoldInconsistentStateException, ReleaseInconsistentStateException, ExitTimeoutException, Exception, StopIteration] drmaa-python-0.7.9/drmaa/helpers.py000066400000000000000000000231771337110701000172350ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2009 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # email: info@riskmap.net # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- # # Author: Enrico Sirola # Author: Dan Blanchard """ internal helpers """ from __future__ import absolute_import, print_function, unicode_literals import sys from collections import namedtuple from ctypes import (byref, c_uint, create_string_buffer, POINTER, pointer, sizeof) from drmaa.const import ATTR_BUFFER, ENCODING, NO_MORE_ELEMENTS from drmaa.errors import error_buffer from drmaa.wrappers import (drmaa_attr_names_t, drmaa_attr_values_t, drmaa_get_attribute, drmaa_get_attribute_names, drmaa_get_next_attr_name, drmaa_get_next_attr_value, drmaa_get_next_job_id, drmaa_get_vector_attribute, drmaa_get_vector_attribute_names, drmaa_job_ids_t, drmaa_release_attr_names, drmaa_release_attr_values, drmaa_release_job_ids, drmaa_run_bulk_jobs, drmaa_set_attribute, drmaa_set_vector_attribute, drmaa_version, STRING) # Python 3 compatability help if sys.version_info < (3, 0): bytes = str str = unicode _BUFLEN = ATTR_BUFFER class BoolConverter(object): """Helper class to convert to/from bool attributes.""" def __init__(self, true=b'y', false=b'n'): if isinstance(true, str): true = true.encode(ENCODING) self.true = true if isinstance(false, str): false = false.encode(ENCODING) self.false = false def to_drmaa(self, value): if value: return self.true else: return self.false def from_drmaa(self, value): if value == self.true: return True else: return False class IntConverter(object): """Helper class to convert to/from int attributes.""" @staticmethod def to_drmaa(value): return bytes(value) @staticmethod def from_drmaa(value): return int(value) class SessionStringAttribute(object): def __init__(self, drmaa_function): self._f = drmaa_function def __get__(self, *args): buf = create_string_buffer(_BUFLEN) c(self._f, buf, sizeof(buf)) return buf.value.decode() Version = namedtuple("Version", "major minor") if sys.version_info < (3, 0): Version.__str__ = lambda x: "{0}.{1}".format(x.major, x.minor).encode(ENCODING) else: Version.__str__ = lambda x: "{0}.{1}".format(x.major, x.minor) class SessionVersionAttribute(object): """A Version attribute.""" def __get__(self, *args): major = c_uint(10) minor = c_uint(10) c(drmaa_version, byref(major), byref(minor)) return Version(major.value, minor.value) class Attribute(object): """ A DRMAA attribute, to be managed with scalar C DRMAA attribute management functions. """ def __init__(self, name, type_converter=None): """ Attribute constructor. :Parameters: `name` : string name of the attribute to be managed, as seen by the underlying C DRMAA `type_converter` a converter to translate attribute values to/from the underlying implementation. See BoolConverter for an example. """ if isinstance(name, str): name = name.encode(ENCODING) self.name = name self.converter = type_converter def __set__(self, instance, value): if self.converter: v = self.converter.to_drmaa(value) elif isinstance(value, str): v = value.encode(ENCODING) else: v = value c(drmaa_set_attribute, instance, self.name, v) def __get__(self, instance, _): attr_buffer = create_string_buffer(ATTR_BUFFER) c(drmaa_get_attribute, instance, self.name, attr_buffer, sizeof(attr_buffer)) if self.converter: return self.converter.from_drmaa(attr_buffer.value) elif isinstance(attr_buffer.value, bytes): return attr_buffer.value.decode() else: return attr_buffer.value class VectorAttribute(object): """ A DRMAA attribute representing a list. To be managed with vector C DRMAA attribute management functions. """ def __init__(self, name): if isinstance(name, str): name = name.encode(ENCODING) self.name = name def __set__(self, instance, value): c(drmaa_set_vector_attribute, instance, self.name, string_vector(value)) def __get__(self, instance, _): return list(vector_attribute_iterator(instance, self.name)) class DictAttribute(object): """ A DRMAA attribute representing a python dict. To be managed with vector C DRMAA attribute management functions. """ def __init__(self, name): if isinstance(name, str): name = name.encode(ENCODING) self.name = name def __set__(self, instance, value): vector = [] for k, v in value.items(): if isinstance(k, bytes): k = k.decode(ENCODING) if isinstance(v, bytes): v = v.decode(ENCODING) vector.append("{0}={1}".format(k, v).encode(ENCODING)) c(drmaa_set_vector_attribute, instance, self.name, string_vector(vector)) def __get__(self, instance, _): x = [i.split('=', 1) for i in list(vector_attribute_iterator(instance, self.name))] return dict(x) def attributes_iterator(attributes): try: buf = create_string_buffer(ATTR_BUFFER) while drmaa_get_next_attr_value(attributes, buf, sizeof(buf)) != NO_MORE_ELEMENTS: yield buf.value.decode() except: drmaa_release_attr_values(attributes) raise else: drmaa_release_attr_values(attributes) def adapt_rusage(rusage): """ Transform a rusage data structure into a dict. Due to the value possibly containing a equal sign make sure we limit the splits to only the first occurrence. """ rv = dict() for attr in attributes_iterator(rusage.contents): k, v = attr.split('=',1) rv[k] = v return rv def vector_attribute_iterator(jt, attr_name): avalues = pointer(POINTER(drmaa_attr_values_t)()) c(drmaa_get_vector_attribute, jt, attr_name, avalues) return attributes_iterator(avalues.contents) def attribute_names_iterator(): attrn_p = pointer(POINTER(drmaa_attr_names_t)()) c(drmaa_get_attribute_names, attrn_p) try: name = create_string_buffer(_BUFLEN) while drmaa_get_next_attr_name(attrn_p.contents, name, _BUFLEN) != NO_MORE_ELEMENTS: yield name.value.decode() except: drmaa_release_attr_names(attrn_p.contents) raise else: drmaa_release_attr_names(attrn_p.contents) def vector_attribute_names_iterator(): attrn_p = pointer(POINTER(drmaa_attr_names_t)()) c(drmaa_get_vector_attribute_names, attrn_p) try: name = create_string_buffer(_BUFLEN) while drmaa_get_next_attr_name(attrn_p.contents, name, _BUFLEN) != NO_MORE_ELEMENTS: yield name.value.decode() except: drmaa_release_attr_names(attrn_p.contents) raise else: drmaa_release_attr_names(attrn_p.contents) def run_bulk_job(jt, start, end, incr=1): jids = pointer(POINTER(drmaa_job_ids_t)()) try: c(drmaa_run_bulk_jobs, jids, jt, start, end, incr) jid = create_string_buffer(_BUFLEN) while drmaa_get_next_job_id(jids.contents, jid, _BUFLEN) != NO_MORE_ELEMENTS: yield jid.value.decode() except StopIteration: pass finally: drmaa_release_job_ids(jids.contents) def c(f, *args): """ A helper function wrapping calls to the C DRMAA functions with error managing code. """ return f(*(args + (error_buffer, sizeof(error_buffer)))) def string_vector(v): vlen = len(v) values = (STRING * (vlen + 1))() for i, el in enumerate(v): if isinstance(el, str): el = el.encode(ENCODING) elif not isinstance(el, bytes): el = str(el).encode(ENCODING) values[i] = STRING(el) values[vlen] = STRING() return values def attribute_setter(obj, attribute_name): """ returns a drmaa attribute setter """ def f(value): "setter for %s" % attribute_name c(drmaa_set_attribute, obj, attribute_name, value) f.__name__ = 'set_' + attribute_name return f def attribute_getter(obj, attribute_name): """ returns a drmaa attribute setter """ def f(): "getter for %s" % attribute_name attr_buffer = create_string_buffer(1024) c(drmaa_get_attribute, obj, attribute_name, attr_buffer, sizeof(attr_buffer)) return attr_buffer.value f.__name__ = 'get_' + attribute_name return f drmaa-python-0.7.9/drmaa/session.py000066400000000000000000000516121337110701000172510ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2008 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- # # Author: Enrico Sirola ''' Everything related to sessions and jobs. ''' from __future__ import absolute_import, print_function, unicode_literals import sys from collections import namedtuple from ctypes import byref, c_int, create_string_buffer, pointer, POINTER, sizeof from drmaa.const import (BLOCK_EMAIL, DEADLINE_TIME, DURATION_HLIMIT, DURATION_SLIMIT, ENCODING, ERROR_PATH, INPUT_PATH, JOB_CATEGORY, JOB_IDS_SESSION_ALL, JOB_IDS_SESSION_ANY, JOB_NAME, JobState, JobControlAction, JobSubmissionState, JOIN_FILES, JS_STATE, NATIVE_SPECIFICATION, OUTPUT_PATH, REMOTE_COMMAND, SIGNAL_BUFFER, START_TIME, status_to_string, string_to_control_action, TIMEOUT_NO_WAIT, TIMEOUT_WAIT_FOREVER, TRANSFER_FILES, V_ARGV, V_EMAIL, V_ENV, WCT_HLIMIT, WCT_SLIMIT, WD) from drmaa.helpers import (adapt_rusage, Attribute, attribute_names_iterator, BoolConverter, c, DictAttribute, IntConverter, run_bulk_job, SessionStringAttribute, SessionVersionAttribute, string_vector, VectorAttribute, Version) from drmaa.wrappers import (drmaa_allocate_job_template, drmaa_attr_values_t, drmaa_control, drmaa_delete_job_template, drmaa_get_contact, drmaa_get_DRM_system, drmaa_get_DRMAA_implementation, drmaa_job_ps, drmaa_job_template_t, drmaa_run_job, drmaa_synchronize, drmaa_wait, drmaa_wcoredump, drmaa_wexitstatus, drmaa_wifaborted, drmaa_wifexited, drmaa_wifsignaled, drmaa_wtermsig, py_drmaa_exit, py_drmaa_init) # Python 3 compatability help if sys.version_info < (3, 0): bytes = str str = unicode JobInfo = namedtuple("JobInfo", """jobId hasExited hasSignal terminatedSignal hasCoreDump wasAborted exitStatus resourceUsage""") class JobTemplate(object): """A job to be submitted to the DRM.""" HOME_DIRECTORY = '$drmaa_hd_ph$' """Home directory placeholder.""" WORKING_DIRECTORY = '$drmaa_wd_ph$' """Working directory placeholder.""" PARAMETRIC_INDEX = '$drmaa_incr_ph$' """Parametric index (for job arrays / bulk jobs) placeholder.""" @property def attributeNames(self): """ The list of supported DRMAA scalar attribute names. This is apparently useless now, and should probably substituted by the list of attribute names of the JobTemplate instances. """ return list(attribute_names_iterator()) # scalar attributes remoteCommand = Attribute(REMOTE_COMMAND) """The command to be executed.""" jobSubmissionState = Attribute(JS_STATE) """The job status.""" workingDirectory = Attribute(WD) """The job working directory.""" jobCategory = Attribute(JOB_CATEGORY) """The job category.""" nativeSpecification = Attribute(NATIVE_SPECIFICATION) """ A (DRM-dependant) opaque string to be passed to the DRM representing other directives. """ blockEmail = Attribute(BLOCK_EMAIL, type_converter=BoolConverter(true='1', false='0')) """False if this job should send an email, True otherwise.""" startTime = Attribute(START_TIME) """The job start time, a partial timestamp string.""" jobName = Attribute(JOB_NAME) """The job Name.""" inputPath = Attribute(INPUT_PATH) """The path to a file representing job's stdin.""" outputPath = Attribute(OUTPUT_PATH) """The path to a file representing job's stdout.""" errorPath = Attribute(ERROR_PATH) """The path to a file representing job's stderr.""" joinFiles = Attribute(JOIN_FILES, type_converter=BoolConverter()) """True if stdin and stdout should be merged, False otherwise.""" # the following is available on ge6.2 only if enabled via cluster # configuration transferFiles = Attribute(TRANSFER_FILES) """ True if file transfer should be enabled, False otherwise. This option might require specific DRM configuration (it does on SGE). """ # the following are apparently not available on ge 6.2 # it will raise if you try to access these attrs deadlineTime = Attribute(DEADLINE_TIME) """The job deadline time, a partial timestamp string.""" hardWallclockTimeLimit = Attribute(WCT_HLIMIT, IntConverter) """ 'Hard' Wallclock time limit, in seconds. The job will be killed by the DRM if it takes more than 'hardWallclockTimeLimit' to complete. """ softWallclockTimeLimit = Attribute(WCT_SLIMIT, IntConverter) """ 'Soft' Wallclock time limit, in seconds. The job will be signaled by the DRM if it takes more than 'hardWallclockTimeLimit' to complete. """ hardRunDurationLimit = Attribute(DURATION_HLIMIT, IntConverter) softRunDurationLimit = Attribute(DURATION_SLIMIT, IntConverter) # vector attributes email = VectorAttribute(V_EMAIL) """email addresses to whom send job completion info.""" args = VectorAttribute(V_ARGV) """The job's command argument list.""" # dict attributes jobEnvironment = DictAttribute(V_ENV) """The job's environment dict.""" _as_parameter_ = None def __init__(self, **kwargs): """ Builds a JobTemplate instance. Attributes can be passed as keyword arguments. """ jt = pointer(POINTER(drmaa_job_template_t)()) c(drmaa_allocate_job_template, jt) self._jt = self._as_parameter_ = jt.contents try: for aname in kwargs: setattr(self, aname, kwargs.get(aname)) except: self.delete() raise def delete(self): """Deallocate the underlying DRMAA job template.""" c(drmaa_delete_job_template, self) def __enter__(self): """context manager enter routine""" return self def __exit__(self, *_): """ context manager exit routine. Stops communication with the DRM. """ self.delete() return False class Session(object): """ The DRMAA Session. This class is the entry point for communicating with the DRM system """ TIMEOUT_WAIT_FOREVER = TIMEOUT_WAIT_FOREVER TIMEOUT_NO_WAIT = TIMEOUT_NO_WAIT JOB_IDS_SESSION_ANY = JOB_IDS_SESSION_ANY JOB_IDS_SESSION_ALL = JOB_IDS_SESSION_ALL contact = SessionStringAttribute(drmaa_get_contact) """ a comma delimited string list containing the contact strings available from the default DRMAA implementation, one element per DRM system available. If called after initialize(), this method returns the contact String for the DRM system to which the session is attached. The returned strings are implementation dependent. """ drmsInfo = SessionStringAttribute(drmaa_get_DRM_system) """ If called before initialize(), this method returns a comma delimited list of DRM systems, one element per DRM system implementation provided. If called after initialize(), this method returns the selected DRM system. The returned String is implementation dependent. """ drmaaImplementation = SessionStringAttribute(drmaa_get_DRMAA_implementation) """ If called before initialize(), this method returns a comma delimited list of DRMAA implementations, one element for each DRMAA implementation provided. If called after initialize(), this method returns the selected DRMAA implementation. The returned String is implementation dependent and may contain the DRM system as a component. """ version = SessionVersionAttribute() """ a Version object containing the major and minor version numbers of the DRMAA library. For DRMAA 1.0, major is 1 and minor is 0. """ def __init__(self, contactString=None): self.contactString = contactString # no return value @staticmethod def initialize(contactString=None): """ Used to initialize a DRMAA session for use. :Parameters: contactString : string or None implementation-dependent string that may be used to specify which DRM system to use This method must be called before any other DRMAA calls. If contactString is None, the default DRM system is used, provided there is only one DRMAA implementation available. If there is more than one DRMAA implementation available, initialize() throws a NoDefaultContactStringSelectedException. initialize() should be called only once, by only one of the threads. The main thread is recommended. A call to initialize() by another thread or additional calls to initialize() by the same thread with throw a SessionAlreadyActiveException. """ py_drmaa_init(contactString) # no return value @staticmethod def exit(): """ Used to disengage from DRM. This routine ends the current DRMAA session but doesn't affect any jobs (e.g., queued and running jobs remain queued and running). exit() should be called only once, by only one of the threads. Additional calls to exit() beyond the first will throw a NoActiveSessionException. """ py_drmaa_exit() # returns JobTemplate instance @staticmethod def createJobTemplate(): """ Allocates a new job template. The job template is used to set the environment for jobs to be submitted. Once the job template has been created, it should also be deleted (via deleteJobTemplate()) when no longer needed. Failure to do so may result in a memory leak. """ return JobTemplate() # takes JobTemplate instance, no return value @staticmethod def deleteJobTemplate(jobTemplate): """ Deallocate a job template. :Parameters: jobTemplate : JobTemplate the job temptare to be deleted This routine has no effect on running jobs. """ jobTemplate.delete() # takes JobTemplate instance, returns string @staticmethod def runJob(jobTemplate): """ Submit a job with attributes defined in the job template. :Parameters: jobTemplate : JobTemplate the template representing the job to be run The returned job identifier is a String identical to that returned from the underlying DRM system. """ jid = create_string_buffer(128) c(drmaa_run_job, jid, sizeof(jid), jobTemplate) return jid.value.decode() # takes JobTemplate instance and num values, returns string list @staticmethod def runBulkJobs(jobTemplate, beginIndex, endIndex, step): """ Submit a set of parametric jobs, each with attributes defined in the job template. :Parameters: jobTemplate : JobTemplate the template representng jobs to be run beginIndex : int index of the first job endIndex : int index of the last job step : int the step between job ids The returned job identifiers are Strings identical to those returned from the underlying DRM system. The JobTemplate class defines a `JobTemplate.PARAMETRIC_INDEX` placeholder for use in specifying paths. This placeholder is used to represent the individual identifiers of the tasks submitted through this method. """ return list(run_bulk_job(jobTemplate, beginIndex, endIndex, step)) # takes string and JobControlAction value, no return value @staticmethod def control(jobId, operation): """ Used to hold, release, suspend, resume, or kill the job identified by jobId. :Parameters: jobId : string if jobId is `Session.JOB_IDS_SESSION_ALL` then this routine acts on all jobs submitted during this DRMAA session up to the moment control() is called. The legal values for action and their meanings are operation : string possible values are: `JobControlAction.SUSPEND` stop the job `JobControlAction.RESUME` (re)start the job `JobControlAction.HOLD` put the job on-hold `JobControlAction.RELEASE` release the hold on the job `JobControlAction.TERMINATE` kill the job To avoid thread races in multithreaded applications, the DRMAA implementation user should explicitly synchronize this call with any other job submission calls or control calls that may change the number of remote jobs. This method returns once the action has been acknowledged by the DRM system, but does not necessarily wait until the action has been completed. Some DRMAA implementations may allow this method to be used to control jobs submitted external to the DRMAA session, such as jobs submitted by other DRMAA session in other DRMAA implementations or jobs submitted via native utilities. """ if isinstance(jobId, str): jobId = jobId.encode(ENCODING) c(drmaa_control, jobId, string_to_control_action(operation)) # takes string list, num value and boolean, no return value @staticmethod def synchronize(jobIds, timeout=-1, dispose=False): """ Waits until all jobs specified by jobList have finished execution. :Parameters: jobIds If jobIds contains `Session.JOB_IDS_SESSION_ALL`, then this method waits for all jobs submitted during this DRMAA session up to the moment synchronize() is called timeout : int maximum time (in seconds) to be waited for the completion of a job. The value `Session.TIMEOUT_WAIT_FOREVER` may be specified to wait indefinitely for a result. The value `Session.TIMEOUT_NO_WAIT` may be specified to return immediately if no result is available. dispose : bool specifies how to treat the reaping of the remote job's internal data record, which includes a record of the job's consumption of system resources during its execution and other statistical information. If set to True, the DRM will dispose of the job's data record at the end of the synchronize() call. If set to False, the data record will be left for future access via the wait() method. It is the responsibility of the application to make sure that either `synchronize()` or `wait()`is called for every job. Not doing so creates a memory leak. Note that calling synchronize() with dispose set to true flushes all accounting information for all jobs in the list. To avoid thread race conditions in multithreaded applications, the DRMAA implementation user should explicitly synchronize this call with any other job submission calls or control calls that may change the number of remote jobs. If the call exits before the timeout has elapsed, all the jobs have been waited on or there was an interrupt. If the invocation exits on timeout, an ExitTimeoutException is thrown. The caller should check system time before and after this call in order to be sure of how much time has passed. """ if dispose: d = 1 else: d = 0 c(drmaa_synchronize, string_vector(jobIds), timeout, d) # takes string and long, returns JobInfo instance @staticmethod def wait(jobId, timeout=-1): """ Wait for a job with jobId to finish execution or fail. :Parameters: `jobId` : str The job id to wait completion for. If the special string, `Session.JOB_IDS_SESSION_ANY`, is provided as the jobId, this routine will wait for any job from the session `timeout` : float The timeout value is used to specify the desired behavior when a result is not immediately available. The value `Session.TIMEOUT_WAIT_FOREVER` may be specified to wait indefinitely for a result. The value `Session.TIMEOUT_NO_WAIT` may be specified to return immediately if no result is available. Alternatively, a number of seconds may be specified to indicate how long to wait for a result to become available This routine is modeled on the wait3 POSIX routine. If the call exits before timeout, either the job has been waited on successfully or there was an interrupt. If the invocation exits on timeout, an `ExitTimeoutException` is thrown. The caller should check system time before and after this call in order to be sure how much time has passed. The routine reaps job data records on a successful call, so any subsequent calls to wait() will fail, throwing an `InvalidJobException`, meaning that the job's data record has been already reaped. This exception is the same as if the job were unknown. (The only case where wait() can be successfully called on a single job more than once is when the previous call to wait() timed out before the job finished.) """ stat = c_int() jid_out = create_string_buffer(128) rusage = pointer(POINTER(drmaa_attr_values_t)()) if isinstance(jobId, str): jobId = jobId.encode(ENCODING) c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout, rusage) res_usage = adapt_rusage(rusage) exited = c_int() c(drmaa_wifexited, byref(exited), stat) aborted = c_int() c(drmaa_wifaborted, byref(aborted), stat) signaled = c_int() c(drmaa_wifsignaled, byref(signaled), stat) coredumped = c_int() if exited.value == 0: c(drmaa_wcoredump, byref(coredumped), stat) exit_status = c_int() c(drmaa_wexitstatus, byref(exit_status), stat) term_signal = create_string_buffer(SIGNAL_BUFFER) if signaled.value == 1: c(drmaa_wtermsig, term_signal, sizeof(term_signal), stat) return JobInfo(jid_out.value.decode(), bool(exited), bool(signaled), term_signal.value.decode(), bool(coredumped), bool(aborted), int(exit_status.value), res_usage) # takes string, returns JobState instance @staticmethod def jobStatus(jobId): """ returns the program status of the job identified by jobId. The possible values returned from this method are: * `JobState.UNDETERMINED`: process status cannot be determined, * `JobState.QUEUED_ACTIVE`: job is queued and active, * `JobState.SYSTEM_ON_HOLD`: job is queued and in system hold, * `JobState.USER_ON_HOLD`: job is queued and in user hold, * `JobState.USER_SYSTEM_ON_HOLD`: job is queued and in user and system hold, * `JobState.RUNNING`: job is running, * `JobState.SYSTEM_SUSPENDED`: job is system suspended, * `JobState.USER_SUSPENDED`: job is user suspended, * `JobState.DONE`: job finished normally, and * `JobState.FAILED`: job finished, but failed. The DRMAA implementation should always get the status of the job from the DRM system unless the status has already been determined to be FAILED or DONE and the status has been successfully cached. Terminated jobs return a FAILED status. """ status = c_int() if isinstance(jobId, str): jobId = jobId.encode(ENCODING) c(drmaa_job_ps, jobId, byref(status)) return status_to_string(status.value) def __enter__(self): """Context manager enter function""" self.initialize(self.contactString) return self def __exit__(self, *_): """Context manager exit function.""" self.exit() return False drmaa-python-0.7.9/drmaa/version.py000066400000000000000000000014351337110701000172510ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2008 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- # ''' This module exists solely for version information so I only have to change it in one place. Based on the suggestion `here. `_ :author: Dan Blanchard (dan.blanchard@gmail.com) ''' __version__ = '0.7.9' VERSION = tuple(int(x) for x in __version__.split('.')) drmaa-python-0.7.9/drmaa/wrappers.py000066400000000000000000000216701337110701000174320ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2009 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # email: info@riskmap.net # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- # # Author: Enrico Sirola """DRMAA C library function wrappers""" from __future__ import absolute_import, print_function, unicode_literals import os import sys from ctypes import (c_char_p, c_int, c_long, c_size_t, c_uint, c_ulong, CDLL, POINTER, RTLD_GLOBAL, sizeof, Structure) from ctypes.util import find_library from drmaa.const import ENCODING from drmaa.errors import error_check, error_buffer # Python 3 compatability help if sys.version_info < (3, 0): bytes = str str = unicode # the name of the OS environment variable optionally # containing the full path to the drmaa library _drmaa_lib_env_name = 'DRMAA_LIBRARY_PATH' if _drmaa_lib_env_name in os.environ: libpath = os.environ[_drmaa_lib_env_name] else: libpath = find_library('drmaa') if libpath is None: raise RuntimeError(('Could not find drmaa library. Please specify its ' + 'full path using the environment variable ' + '{0}').format(_drmaa_lib_env_name)) _lib = CDLL(libpath, mode=RTLD_GLOBAL) STRING = c_char_p size_t = c_ulong ptrdiff_t = c_int drmaa_init = _lib.drmaa_init drmaa_init.restype = error_check drmaa_init.argtypes = [STRING, STRING, size_t] drmaa_exit = _lib.drmaa_exit drmaa_exit.restype = error_check drmaa_exit.argtypes = [STRING, size_t] def py_drmaa_init(contact=None): if isinstance(contact, str): contact = contact.encode(ENCODING) return _lib.drmaa_init(contact, error_buffer, sizeof(error_buffer)) _lib.drmaa_exit.argtypes = [c_char_p, c_size_t] _lib.drmaa_init.restype = error_check def py_drmaa_exit(): return _lib.drmaa_exit(error_buffer, sizeof(error_buffer)) # structures class drmaa_job_template_s(Structure): pass drmaa_job_template_t = drmaa_job_template_s drmaa_job_template_s._fields_ = [] class drmaa_attr_names_s(Structure): pass drmaa_attr_names_t = drmaa_attr_names_s drmaa_attr_names_s._fields_ = [] class drmaa_attr_values_s(Structure): pass drmaa_attr_values_t = drmaa_attr_values_s drmaa_attr_values_s._fields_ = [] class drmaa_job_ids_s(Structure): pass drmaa_job_ids_t = drmaa_job_ids_s drmaa_job_ids_s._fields_ = [] drmaa_get_contact = _lib.drmaa_get_contact drmaa_get_contact.restype = error_check drmaa_get_contact.argtypes = [STRING, size_t, STRING, size_t] drmaa_version = _lib.drmaa_version drmaa_version.restype = error_check drmaa_version.argtypes = [POINTER(c_uint), POINTER(c_uint), STRING, size_t] drmaa_get_DRM_system = _lib.drmaa_get_DRM_system drmaa_get_DRM_system.restype = error_check drmaa_get_DRM_system.argtypes = [STRING, size_t, STRING, size_t] drmaa_get_DRMAA_implementation = _lib.drmaa_get_DRMAA_implementation drmaa_get_DRMAA_implementation.restype = error_check drmaa_get_DRMAA_implementation.argtypes = [STRING, size_t, STRING, size_t] drmaa_allocate_job_template = _lib.drmaa_allocate_job_template drmaa_allocate_job_template.restype = error_check drmaa_allocate_job_template.argtypes = [POINTER(POINTER(drmaa_job_template_t)), STRING, size_t] drmaa_delete_job_template = _lib.drmaa_delete_job_template drmaa_delete_job_template.restype = error_check drmaa_delete_job_template.argtypes = [POINTER(drmaa_job_template_t), STRING, size_t] drmaa_set_attribute = _lib.drmaa_set_attribute drmaa_set_attribute.restype = error_check drmaa_set_attribute.argtypes = [POINTER(drmaa_job_template_t), STRING, STRING, STRING, size_t] drmaa_get_attribute = _lib.drmaa_get_attribute drmaa_get_attribute.restype = error_check drmaa_get_attribute.argtypes = [POINTER(drmaa_job_template_t), STRING, STRING, size_t, STRING, size_t] drmaa_get_next_attr_name = _lib.drmaa_get_next_attr_name drmaa_get_next_attr_name.restype = c_int drmaa_get_next_attr_name.argtypes = [POINTER(drmaa_attr_names_t), STRING, size_t] drmaa_get_next_attr_value = _lib.drmaa_get_next_attr_value drmaa_get_next_attr_value.restype = c_int drmaa_get_next_attr_value.argtypes = [POINTER(drmaa_attr_values_t), STRING, size_t] drmaa_get_next_job_id = _lib.drmaa_get_next_job_id drmaa_get_next_job_id.restype = error_check drmaa_get_next_job_id.argtypes = [POINTER(drmaa_job_ids_t), STRING, size_t] drmaa_release_attr_names = _lib.drmaa_release_attr_names drmaa_release_attr_names.restype = None drmaa_release_attr_names.argtypes = [POINTER(drmaa_attr_names_t)] drmaa_release_attr_values = _lib.drmaa_release_attr_values drmaa_release_attr_values.restype = None drmaa_release_attr_values.argtypes = [POINTER(drmaa_attr_values_t)] drmaa_release_job_ids = _lib.drmaa_release_job_ids drmaa_release_job_ids.restype = None drmaa_release_job_ids.argtypes = [POINTER(drmaa_job_ids_t)] drmaa_set_vector_attribute = _lib.drmaa_set_vector_attribute drmaa_set_vector_attribute.restype = error_check drmaa_set_vector_attribute.argtypes = [POINTER(drmaa_job_template_t), STRING, POINTER(STRING), STRING, size_t] drmaa_get_vector_attribute = _lib.drmaa_get_vector_attribute drmaa_get_vector_attribute.restype = error_check drmaa_get_vector_attribute.argtypes = [POINTER(drmaa_job_template_t), STRING, POINTER(POINTER(drmaa_attr_values_t)), STRING, size_t] drmaa_get_attribute_names = _lib.drmaa_get_attribute_names drmaa_get_attribute_names.restype = error_check drmaa_get_attribute_names.argtypes = [POINTER(POINTER(drmaa_attr_names_t)), STRING, size_t] drmaa_get_vector_attribute_names = _lib.drmaa_get_vector_attribute_names drmaa_get_vector_attribute_names.restype = error_check drmaa_get_vector_attribute_names.argtypes = [POINTER(POINTER(drmaa_attr_names_t)), STRING, size_t] try: drmaa_get_num_attr_names = _lib.drmaa_get_num_attr_names drmaa_get_num_attr_names.restype = c_int drmaa_get_num_attr_names.argtypes = [POINTER(drmaa_attr_names_t), POINTER(c_int)] drmaa_get_num_attr_values = _lib.drmaa_get_num_attr_values drmaa_get_num_attr_values.restype = c_int drmaa_get_num_attr_values.argtypes = [POINTER(drmaa_attr_values_t), POINTER(c_int)] except AttributeError: # the above are present from 1.0 onward only pass drmaa_run_job = _lib.drmaa_run_job drmaa_run_job.restype = error_check drmaa_run_job.argtypes = [STRING, size_t, POINTER(drmaa_job_template_t), STRING, size_t] drmaa_run_bulk_jobs = _lib.drmaa_run_bulk_jobs drmaa_run_bulk_jobs.restype = error_check drmaa_run_bulk_jobs.argtypes = [POINTER(POINTER(drmaa_job_ids_t)), POINTER(drmaa_job_template_t), c_int, c_int, c_int, STRING, size_t] drmaa_control = _lib.drmaa_control drmaa_control.restype = error_check drmaa_control.argtypes = [STRING, c_int, STRING, size_t] drmaa_synchronize = _lib.drmaa_synchronize drmaa_synchronize.restype = error_check drmaa_synchronize.argtypes = [POINTER(STRING), c_long, c_int, STRING, size_t] drmaa_wait = _lib.drmaa_wait drmaa_wait.restype = error_check drmaa_wait.argtypes = [STRING, STRING, size_t, POINTER(c_int), c_long, POINTER(POINTER(drmaa_attr_values_t)), STRING, size_t] drmaa_wifexited = _lib.drmaa_wifexited drmaa_wifexited.restype = error_check drmaa_wifexited.argtypes = [POINTER(c_int), c_int, STRING, size_t] drmaa_wexitstatus = _lib.drmaa_wexitstatus drmaa_wexitstatus.restype = error_check drmaa_wexitstatus.argtypes = [POINTER(c_int), c_int, STRING, size_t] drmaa_wifsignaled = _lib.drmaa_wifsignaled drmaa_wifsignaled.restype = error_check drmaa_wifsignaled.argtypes = [POINTER(c_int), c_int, STRING, size_t] drmaa_wtermsig = _lib.drmaa_wtermsig drmaa_wtermsig.restype = error_check drmaa_wtermsig.argtypes = [STRING, size_t, c_int, STRING, size_t] drmaa_wcoredump = _lib.drmaa_wcoredump drmaa_wcoredump.restype = error_check drmaa_wcoredump.argtypes = [POINTER(c_int), c_int, STRING, size_t] drmaa_wifaborted = _lib.drmaa_wifaborted drmaa_wifaborted.restype = error_check drmaa_wifaborted.argtypes = [POINTER(c_int), c_int, STRING, size_t] drmaa_job_ps = _lib.drmaa_job_ps drmaa_job_ps.restype = error_check drmaa_job_ps.argtypes = [STRING, POINTER(c_int), STRING, size_t] drmaa_strerror = _lib.drmaa_strerror drmaa_strerror.restype = STRING drmaa_strerror.argtypes = [c_int] drmaa-python-0.7.9/examples/000077500000000000000000000000001337110701000157415ustar00rootroot00000000000000drmaa-python-0.7.9/examples/example.py000066400000000000000000000037301337110701000177510ustar00rootroot00000000000000#!/bin/python from __future__ import print_function import drmaa import os from sys import argv, exit from time import sleep from pprint import pprint NBULKS = 1 JOB_CHUNK = 3 OPATH=":"+drmaa.JobTemplate.HOME_DIRECTORY+'/DRMAA_JOB_OUT' def init_job_template(jt, path, args, as_bulk_job): jt.workingDirectory = drmaa.JobTemplate.HOME_DIRECTORY jt.environment = {'a': 'b', 'c':'d',} jt.remoteCommand = path jt.args = args jt.joinFiles=True # jt.startTime=datetime.now() # print("start time is: ", jt.startTime) if as_bulk_job: jt.outputPath=OPATH+'.'+drmaa.JobTemplate.PARAMETRIC_INDEX else: jt.outputPath=OPATH return jt def main(): if len(argv) < 2: print("usage: example.py ") exit(1) job_path=argv[1] s=drmaa.Session() s.initialize() # submit some bulk jobs jt=init_job_template(s.createJobTemplate(), job_path, argv[2:], True) all_jobids = [] for i in range(NBULKS): all_jobids += s.runBulkJobs(jt, 1, JOB_CHUNK, 1) sleep(1) print("submitted bulk jobs with jobids:") pprint(all_jobids) # submit some sequential jobs s.deleteJobTemplate(jt) del jt jt=init_job_template(s.createJobTemplate(), job_path, argv[2:], False) for i in range(NBULKS): all_jobids.append(s.runJob(jt)) sleep(1) s.synchronize(all_jobids, drmaa.Session.TIMEOUT_WAIT_FOREVER, False) print("synchronized with all jobs") for jid in all_jobids: print('-' * 76) info=s.wait(jid, drmaa.Session.TIMEOUT_WAIT_FOREVER) print("""\ id: %(jobId)s exited: %(hasExited)s signaled: %(hasSignal)s with signal (id signaled): %(terminatedSignal)s dumped core: %(hasCoreDump)s aborted: %(wasAborted)s resource usage: %(resourceUsage)s """ % info._asdict()) if __name__=='__main__': main() drmaa-python-0.7.9/examples/example1.1.py000066400000000000000000000010511337110701000201630ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa def main(): """Create a session, show that each session has an id, use session id to disconnect, then reconnect. Then exit""" s = drmaa.Session() s.initialize() print('A session was started successfully') response = s.contact print('session contact returns: ' + response) s.exit() print('Exited from session') s.initialize(response) print('Session was restarted successfully') s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example1.py000066400000000000000000000004151337110701000200270ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa def main(): """Create a drmaa session and exit""" s=drmaa.Session() s.initialize() print('A session was started successfully') s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example2.1.py000066400000000000000000000011511337110701000201650ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa import os def main(): """Submit an array job. Note, need file called sleeper.sh in home directory. """ s = drmaa.Session() s.initialize() print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.getcwd() + '/sleeper.sh' jt.args = ['42','Simon says:'] jt.joinFiles=True jobid = s.runBulkJobs(jt,1,30,2) print('Your job has been submitted with id ' + str(jobid)) print('Cleaning up') s.deleteJobTemplate(jt) s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example2.py000066400000000000000000000011301337110701000200230ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa import os def main(): """Submit a job. Note, need file called sleeper.sh in current directory. """ s = drmaa.Session() s.initialize() print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.getcwd() + '/sleeper.sh' jt.args = ['42','Simon says:'] jt.joinFiles=True jobid = s.runJob(jt) print('Your job has been submitted with id ' + jobid) print('Cleaning up') s.deleteJobTemplate(jt) s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example3.1.py000066400000000000000000000013321337110701000201670ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa import os def main(): """Submit an array job, and wait for all of them to finish. Note, need file called sleeper.sh in home directory. """ s = drmaa.Session() s.initialize() print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.getcwd() + '/sleeper.sh' jt.args = ['42','Simon says:'] jt.joinFiles=True joblist = s.runBulkJobs(jt,1,30,2) print('Your job has been submitted with id ' + str(joblist)) s.synchronize(joblist, drmaa.Session.TIMEOUT_WAIT_FOREVER, True) print('Cleaning up') s.deleteJobTemplate(jt) s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example3.2.py000066400000000000000000000020251337110701000201700ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa import os def main(): """Submit an array job, wait for them to finish, and collect results. This is slightly different from the example from sunsource because it only waits for the jobs that it submitted. """ s = drmaa.Session() s.initialize() print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.getcwd() + '/sleeper.sh' jt.args = ['42','Simon says:'] jt.joinFiles=True joblist = s.runBulkJobs(jt,1,30,2) print('Your job has been submitted with id ' + str(joblist)) s.synchronize(joblist, drmaa.Session.TIMEOUT_WAIT_FOREVER, False) for curjob in joblist: print('Collecting job ' + curjob) retval = s.wait(curjob, drmaa.Session.TIMEOUT_WAIT_FOREVER) print('Job: ' + str(retval.jobId) + ' finished with status ' + str(retval.hasExited)) print('Cleaning up') s.deleteJobTemplate(jt) s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example3.py000066400000000000000000000014141337110701000200310ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa import os def main(): """Submit a job and wait for it to finish. Note, need file called sleeper.sh in home directory. """ s = drmaa.Session() s.initialize() print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.getcwd() + '/sleeper.sh' jt.args = ['42','Simon says:'] jt.joinFiles = True jobid = s.runJob(jt) print('Your job has been submitted with id ' + jobid) retval = s.wait(jobid, drmaa.Session.TIMEOUT_WAIT_FOREVER) print('Job: ' + str(retval.jobId) + ' finished with status ' + str(retval.hasExited)) print('Cleaning up') s.deleteJobTemplate(jt) s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example4.py000066400000000000000000000013311337110701000200300ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa import os def main(): """Submit a job, then kill it. Note, need file called sleeper.sh in home directory. """ s = drmaa.Session() s.initialize() print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.getcwd() + '/sleeper.sh' jt.args = ['42','Simon says:'] jt.joinFiles = True jobid = s.runJob(jt) print('Your job has been submitted with id ' + jobid) # options are: SUSPEND, RESUME, HOLD, RELEASE, TERMINATE s.control(jobid, drmaa.JobControlAction.TERMINATE) print('Cleaning up') s.deleteJobTemplate(jt) s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example5.py000066400000000000000000000030201337110701000200260ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa import time import os def main(): """Submit a job, and check its progress. Note, need file called sleeper.sh in home directory. """ s = drmaa.Session() s.initialize() print('Creating job template') jt = s.createJobTemplate() jt.remoteCommand = os.getcwd() + '/sleeper.sh' jt.args = ['42','Simon says:'] jt.joinFiles=True jobid = s.runJob(jt) print('Your job has been submitted with id ' + jobid) # Who needs a case statement when you have dictionaries? decodestatus = { drmaa.JobState.UNDETERMINED: 'process status cannot be determined', drmaa.JobState.QUEUED_ACTIVE: 'job is queued and active', drmaa.JobState.SYSTEM_ON_HOLD: 'job is queued and in system hold', drmaa.JobState.USER_ON_HOLD: 'job is queued and in user hold', drmaa.JobState.USER_SYSTEM_ON_HOLD: 'job is queued and in user and system hold', drmaa.JobState.RUNNING: 'job is running', drmaa.JobState.SYSTEM_SUSPENDED: 'job is system suspended', drmaa.JobState.USER_SUSPENDED: 'job is user suspended', drmaa.JobState.DONE: 'job finished normally', drmaa.JobState.FAILED: 'job finished, but failed', } for ix in range(10): print('Checking ' + str(ix) + ' of 10 times') print(decodestatus[s.jobStatus(jobid)]) time.sleep(5) print('Cleaning up') s.deleteJobTemplate(jt) s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/example6.py000066400000000000000000000007621337110701000200410ustar00rootroot00000000000000#!/usr/bin/env python from __future__ import print_function import drmaa def main(): """Query the system.""" s = drmaa.Session() s.initialize() print('A DRMAA object was created') print('Supported contact strings: ' + s.contact) print('Supported DRM systems: ' + str(s.drmsInfo)) print('Supported DRMAA implementations: ' + str(s.drmaaImplementation)) print('Version ' + str(s.version)) print('Exiting') s.exit() if __name__=='__main__': main() drmaa-python-0.7.9/examples/sleeper.sh000077500000000000000000000001211337110701000177310ustar00rootroot00000000000000#!/bin/bash echo "Hello World, the answer is $1" sleep 3s echo "$2 Bye world!" drmaa-python-0.7.9/license.txt000066400000000000000000000027171337110701000163150ustar00rootroot00000000000000Copyright (c) 2009, StatPro Italia srl All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of StatPro Italia srl nor the names of the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY StatPro Italia srl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL StatPro Italia srl BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. drmaa-python-0.7.9/setup.cfg000066400000000000000000000001031337110701000157360ustar00rootroot00000000000000[metadata] license_file = license.txt [bdist_wheel] universal = 1 drmaa-python-0.7.9/setup.py000066400000000000000000000040421337110701000156350ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2009 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- # # Author: Enrico Sirola # Author: Dan Blanchard from setuptools import setup, find_packages packages = find_packages() package_data = dict([ (x, ['test/*.py']) for x in packages]) # To get around the fact that you can't import stuff from packages in setup.py exec(compile(open('drmaa/version.py').read(), 'drmaa/version.py', 'exec')) # (we use the above instead of execfile for Python 3.x compatibility) def readme(): with open('README.rst') as f: return f.read() setup(name="drmaa", version=__version__, packages=packages, package_data=package_data, author="Dan Blanchard", author_email="dan.blanchard@gmail.com", description="a python DRMAA library", long_description=readme(), license="BSD", keywords="python grid hpc drmaa", url="https://github.com/pygridtools/drmaa-python", tests_require='nose', test_suite='nose.collector', classifiers=["Development Status :: 4 - Beta", "Operating System :: OS Independent", "Intended Audience :: System Administrators", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries", "Topic :: System :: Distributed Computing"]) drmaa-python-0.7.9/test/000077500000000000000000000000001337110701000151025ustar00rootroot00000000000000drmaa-python-0.7.9/test/testcontext.py000066400000000000000000000012001337110701000200310ustar00rootroot00000000000000''' Tests related to with using context managers. ''' from __future__ import absolute_import, print_function, unicode_literals from drmaa import Session def test_with_session(): """'with' statement works with Session""" with Session() as s: print(s.version) print(s.contact) print(s.drmsInfo) print(s.drmaaImplementation) def test_with_jt(): """'with' statement works with JobTemplate""" s = Session() s.initialize() with s.createJobTemplate() as jt: jt.remoteCommand = 'sleep' jt.args = ['10'] jid = s.runJob(jt) print(s.wait(jid)) s.exit() drmaa-python-0.7.9/test/testmisc.py000066400000000000000000000013201337110701000173030ustar00rootroot00000000000000''' Test miscenallenous helper functions. ''' from __future__ import absolute_import, print_function, unicode_literals from unittest import TestCase from drmaa import Session class Misc(TestCase): def setUp(self): self.s = Session() def test_drmaa_get_contact(self): """contact attribute works""" print(self.s.contact) def test_drmaa_version(self): """version attribute works""" print(self.s.version) def test_drmaa_get_DRM_system(self): """DRM system attribute works""" print(self.s.drmsInfo) def test_drmaa_get_DRMAA_implementation(self): """DRMAA implementation attribute works""" print(self.s.drmaaImplementation) drmaa-python-0.7.9/test/testwrap.py000066400000000000000000000146211337110701000173310ustar00rootroot00000000000000# ----------------------------------------------------------- # Copyright (C) 2009 StatPro Italia s.r.l. # # StatPro Italia # Via G. B. Vico 4 # I-20123 Milano # ITALY # # phone: +39 02 96875 1 # fax: +39 02 96875 605 # # email: info@riskmap.net # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the license for more details. # ----------------------------------------------------------- """ test module for the functional interface """ from __future__ import absolute_import, print_function, unicode_literals import sys import unittest from os import environ from nose.tools import eq_ from drmaa import Session, JobTemplate from drmaa.const import (JobControlAction, JobSubmissionState, PLACEHOLDER_HD, SUBMISSION_STATE_ACTIVE) # Python 3 compatability help if sys.version_info < (3, 0): bytes = str str = unicode def setup(): "initialize DRMAA library" Session.initialize() def teardown(): "finalize DRMAA session" Session.exit() def test_allocate(): "job template allocation" jt = Session.createJobTemplate() Session.deleteJobTemplate(jt) class SubmitBase(unittest.TestCase): def setUp(self): self.jt = jt = Session.createJobTemplate() jt.remoteCommand = 'python' jt.args = ['-c', "print('hello from python!')"] if hasattr(self, 'jt_tweaks'): self.jt_tweaks() self.jid = Session.runJob(jt) def tearDown(self): Session.deleteJobTemplate(self.jt) class EnvironmentTest(SubmitBase): def jt_tweaks(self): environ['PIPPO'] = 'aaaa' self.jt.args = (["-c", ("from os import environ as env; assert ('PIPPO' in " + "env) and (env['PIPPO'] == 'aaaa')")]) self.jt.jobEnvironment = environ def test_environment(self): """environment variables are correctly passed to submitted jobs""" jinfo = Session.wait(self.jid) eq_(jinfo.jobId, self.jid) assert hasattr(jinfo, 'hasExited') assert hasattr(jinfo, 'exitStatus') and jinfo.exitStatus == 0 class Submit(SubmitBase): def test_run_bulk(self): """run bulk job""" jids = Session.runBulkJobs(self.jt, 1, 2, 1) def test_wait(self): """waiting for job completion""" jinfo = Session.wait(self.jid) eq_(jinfo.jobId, self.jid) assert hasattr(jinfo, 'hasExited') assert hasattr(jinfo, 'hasExited') and type(jinfo.hasExited) is bool assert hasattr(jinfo, 'hasSignal') and type(jinfo.hasSignal) is bool assert hasattr(jinfo, 'terminatedSignal') and type(jinfo.terminatedSignal) is str assert hasattr(jinfo, 'hasCoreDump') and type(jinfo.hasCoreDump) is bool assert hasattr(jinfo, 'wasAborted') and type(jinfo.wasAborted) is bool assert hasattr(jinfo, 'exitStatus') and type(jinfo.exitStatus) is int assert hasattr(jinfo, 'resourceUsage') and type(jinfo.resourceUsage) is dict def test_sync(self): """sync with a job""" Session.synchronize(self.jid) def test_control_terminate(self): """control/terminate works""" Session.control(self.jid, JobControlAction.TERMINATE) Session.synchronize(self.jid, Session.TIMEOUT_WAIT_FOREVER, False) try: Session.wait(self.jid, Session.TIMEOUT_WAIT_FOREVER) except Exception as e: assert e.args[0].startswith('code 24') # no rusage class JobTemplateTests(unittest.TestCase): def setUp(self): self.jt = Session.createJobTemplate() def test_scalar_attributes(self): """scalar attributes work""" for name, value in [("remoteCommand", 'cat'), ("jobSubmissionState", SUBMISSION_STATE_ACTIVE), ("workingDirectory", JobTemplate.HOME_DIRECTORY), ("nativeSpecification", '-shell yes'), ("blockEmail", False), ("jobName", 'pippo'), ("inputPath", ":%s" % PLACEHOLDER_HD), ("outputPath", ":%s/pippo.out" % PLACEHOLDER_HD), ("errorPath", ":%s/pippo.out" % PLACEHOLDER_HD), ("joinFiles", True)]: setattr(self.jt, name, value) eq_(getattr(self.jt, name), value) # skipping this. the parameters above have to be tweaked a bit def xtest_tmp(self): self.test_scalar_attributes() self.jt.args = ['.colordb'] jid = Session.runJob(self.jt) jinfo = Session.wait(jid) print(jinfo) def test_vector_attributes(self): """vector attributes work""" args = [10, 'de', 'arglebargle'] self.jt.args = args eq_(self.jt.args, ['10', 'de', 'arglebargle']) em = ['baz@quz.edu', 'foo@bar.com'] self.jt.email = em eq_(self.jt.email, em) def test_dict_attribute(self): """dict attributes work""" from drmaa.const import ATTR_BUFFER self.jt.jobEnvironment = environ for x in environ: # attribute values could be truncated. For some reason, # GE returns the first 1014 chars available (!) eq_(environ[x][:ATTR_BUFFER - 10], self.jt.jobEnvironment[x][:ATTR_BUFFER - 10]) def test_attribute_names(self): """attribute names work""" assert len(self.jt.attributeNames) > 0 def test_block_email(self): """blockEmail works""" self.jt.blockEmail = True assert self.jt.blockEmail self.jt.blockEmail = False assert not self.jt.blockEmail def test_join_files(self): """joinFiles works""" self.jt.joinFiles = True assert self.jt.joinFiles self.jt.joinFiles = False assert not self.jt.joinFiles def test_submission_state(self): """submission state attributes work""" self.jt.jobSubmissionState = JobSubmissionState.HOLD_STATE eq_(self.jt.jobSubmissionState, JobSubmissionState.HOLD_STATE) self.jt.jobSubmissionState = JobSubmissionState.ACTIVE_STATE eq_(self.jt.jobSubmissionState, JobSubmissionState.ACTIVE_STATE) def tearDown(self): Session.deleteJobTemplate(self.jt) drmaa-python-0.7.9/travis/000077500000000000000000000000001337110701000154335ustar00rootroot00000000000000drmaa-python-0.7.9/travis/host_template000066400000000000000000000002431337110701000202250ustar00rootroot00000000000000hostname localhost load_scaling NONE complex_values NONE user_lists arusers xuser_lists NONE projects NONE xprojects NONE usage_scaling NONE report_variables NONE drmaa-python-0.7.9/travis/install_sge.sh000077500000000000000000000024451337110701000203030ustar00rootroot00000000000000#!/bin/bash # This script installs and configures a Sun Grid Engine installation for use # on a Travis instance. # # Written by Dan Blanchard (dan.blanchard@gmail.com), September 2013 cd travis sudo apt-get update -qq echo "gridengine-master shared/gridenginemaster string localhost" | sudo debconf-set-selections echo "gridengine-master shared/gridenginecell string default" | sudo debconf-set-selections echo "gridengine-master shared/gridengineconfig boolean true" | sudo debconf-set-selections sudo apt-get install gridengine-common gridengine-master # Do this in a separate step to give master time to start sudo apt-get install libdrmaa1.0 gridengine-client gridengine-exec export CORES=$(grep -c '^processor' /proc/cpuinfo) sed -i -r "s/template/$USER/" user_template sudo qconf -Auser user_template sudo qconf -au $USER arusers sudo qconf -as localhost export LOCALHOST_IN_SEL=$(qconf -sel | grep -c 'localhost') if [ $LOCALHOST_IN_SEL != "1" ]; then sudo qconf -Ae host_template; else sudo qconf -Me host_template; fi sed -i -r "s/UNDEFINED/$CORES/" queue_template sudo qconf -Ap smp_template sudo qconf -Aq queue_template echo "Printing queue info to verify that things are working correctly." qstat -f -q all.q -explain a echo "You should see sge_execd and sge_qmaster running below:" ps aux | grep "sge" drmaa-python-0.7.9/travis/queue_template000066400000000000000000000015451337110701000204020ustar00rootroot00000000000000qname all.q hostlist localhost seq_no 0 load_thresholds np_load_avg=1.75 suspend_thresholds NONE nsuspend 1 suspend_interval 00:05:00 priority 0 min_cpu_interval 00:05:00 processors UNDEFINED qtype BATCH INTERACTIVE ckpt_list NONE pe_list make smp rerun FALSE slots UNDEFINED tmpdir /tmp shell /bin/bash prolog NONE epilog NONE shell_start_mode posix_compliant starter_method NONE suspend_method NONE resume_method NONE terminate_method NONE notify 00:00:60 owner_list NONE user_lists arusers xuser_lists NONE subordinate_list NONE complex_values NONE projects NONE xprojects NONE calendar NONE initial_state default s_rt INFINITY h_rt INFINITY s_cpu INFINITY h_cpu INFINITY s_fsize INFINITY h_fsize INFINITY s_data INFINITY h_data INFINITY s_stack INFINITY h_stack INFINITY s_core INFINITY h_core INFINITY s_rss INFINITY h_rss INFINITY s_vmem INFINITY h_vmem INFINITY drmaa-python-0.7.9/travis/smp_template000066400000000000000000000004261337110701000200520ustar00rootroot00000000000000pe_name smp slots 999 user_lists NONE xuser_lists NONE start_proc_args /bin/true stop_proc_args /bin/true allocation_rule $pe_slots control_slaves FALSE job_is_first_task TRUE urgency_slots min accounting_summary FALSE drmaa-python-0.7.9/travis/user_template000066400000000000000000000001041337110701000202220ustar00rootroot00000000000000name template oticket 0 fshare 0 delete_time 0 default_project NONE