diff --git a/drmaa/__init__.py b/drmaa/__init__.py index 411e344..1602692 100644 --- a/drmaa/__init__.py +++ b/drmaa/__init__.py @@ -32,6 +32,8 @@ from __future__ import absolute_import, print_function, unicode_literals +import logging + from .const import (ATTR_BUFFER, BLOCK_EMAIL, CONTACT_BUFFER, control_action_to_string, DEADLINE_TIME, DRM_SYSTEM_BUFFER, DRMAA_IMPLEMENTATION_BUFFER, DURATION_HLIMIT, @@ -98,3 +100,8 @@ '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'] + + +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) +logger.addHandler(logging.NullHandler()) diff --git a/drmaa/helpers.py b/drmaa/helpers.py index 7ba0ff0..5a34066 100644 --- a/drmaa/helpers.py +++ b/drmaa/helpers.py @@ -26,11 +26,14 @@ from __future__ import absolute_import, print_function, unicode_literals +import logging import sys from collections import namedtuple from ctypes import (byref, c_uint, create_string_buffer, POINTER, pointer, sizeof) +from wurlitzer import pipes + 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, @@ -55,6 +58,11 @@ _BUFLEN = ATTR_BUFFER +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) +logger.addHandler(logging.NullHandler()) + + class BoolConverter(object): """Helper class to convert to/from bool attributes.""" @@ -299,8 +307,19 @@ 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)))) + with pipes() as (stdout, stderr): + result = f(*(args + (error_buffer, sizeof(error_buffer)))) + + for line in stdout.readline(): + if line: + logger.debug(line) + + for line in stderr.readline(): + if line: + logger.debug(line) + + return result def string_vector(v): vlen = len(v) diff --git a/setup.py b/setup.py index be956c9..9ea832b 100644 --- a/setup.py +++ b/setup.py @@ -42,6 +42,7 @@ def readme(): license="BSD", keywords="python grid hpc drmaa", url="https://github.com/pygridtools/drmaa-python", + install_requires=["wurlitzer"], tests_require='nose', test_suite='nose.collector', classifiers=["Development Status :: 4 - Beta",