-
Notifications
You must be signed in to change notification settings - Fork 9
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
Work on moving stdout / stderr redirection from desispec to desiutil #153
Conversation
desiutil so that it can be used in other packages. The unit tests are not yet working, since redirecting stdout actually breaks the unit test runner (which has a persistent handle to sys.stdout).
The MPI test script cannot be spawned from within the unit test runner, so I simply print out the command to run. |
I've run two checks (no MPI). |
There is one transient test failure unrelated to this PR, but the rest seems to be working. After this work is merged we can use this in fiberassign and switch desispec over to this version of the redirection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very complex module, and I will probably need to take more time than this to fully digest it. So this first review is just to catch the obvious things. I'll do a second review after the first round is addressed.
I'll go wrap the libc handle fetching in a function. Just for the record, although this is "complicated" code, it is a minor reworking of code that has been used in https://github.com/desihub/desispec/blob/master/py/desispec/parallel.py#L292 This version of the code has been improved to be more resilient against the wrapped code raising an exception. And this version of the code now has explicit unit tests, unlike the desispec version. |
OK, but again, we are not using setup.py for tests now. |
@sbailey, I'd like your review here. We're getting bogged down in changes to Travis tests that I feel are not necessary, but we have not come to a consensus. I also don't know how urgent this is, and because of the test issue, I have not had time to review the module really thoroughly for other problems. Could you please chime in? |
@weaverba137 , do you understand at least why I need to install the package first? I really am not trying to make more work for myself just for fun. The python Just to reiterate- a messier version of this code (with no unit tests at all) is already in use in desispec. This PR was an effort to put the code in a common place and clean it up and make some tests. |
@tskisner, honestly, no, I do not understand that, in part because I haven't had time to dig into the details of the module itself. Without delving into that, I don't know whether there is a more clever way to manipulate |
Wearing my manager hat, summarizing my understanding of this PR:
Executive decision:
|
@sbailey, thank you. I also remember now that we had issues in the past along the lines of "is this testing the bare git clone, or code that is installed somewhere else". I will take one more look at the module itself this afternoon, and I will approve and merge after that. I added |
Is the function |
_c_stdout = ctypes.c_void_p.in_dll(_libc, '__stdoutp')
_c_stderr = ctypes.c_void_p.in_dll(_libc, '__stdoutp') Is this really the correct calling sequence for MacOS/Darwin? Stdout and stderr have exactly the same names? |
if sys.version_info[0] < 3:
sys.stdout = os.fdopen(fd_out, "wb")
sys.stderr = os.fdopen(fd_err, "wb")
else:
# Python 3 case
sys.stdout = io.TextIOWrapper(os.fdopen(fd_out, 'wb'))
sys.stderr = io.TextIOWrapper(os.fdopen(fd_err, 'wb')) I'm pretty sure we don't need to support Python 2 in this module. |
def _open_redirect(filename):
# Open python file, which creates low-level POSIX file
# descriptor.
file_handle = open(filename, "w")
# ... In most other places, files are opened |
log.info("Begin log redirection to %s at %s", to, time.asctime()) Since you're using |
Why are there so many calls to |
Now that I've finally looked over the module in detail, there are several more points to address before this can be merged. Hopefully these can be done quickly. |
I made these changes:
I am intentionally getting a new log handle each time I need it, since I recall problems with this in past. Likely something to do with the redirect modifying the logger. |
I verified that |
Thanks @sbailey . Looks like travis may never run, so merge if you are happy with it. |
Two updates:
Travis is completely bogged down (tests aren't getting through on multiple repos), but I verified that they pass on my laptop (Mac) and at NERSC so I'll merge anyway without Travis so that we can proceed with a new tag. This will flag that PR as failing tests, but ok. |
The unit tests are not yet working, since redirecting stdout actually breaks the unit test runner (which has a persistent handle to sys.stdout). I am working on a unit test that runs the redirection in a subprocess.