Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Redirect C stdout & stderr to log #70

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions drmaa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
21 changes: 20 additions & 1 deletion drmaa/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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."""
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down