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

Remove ds9 warnings when run under Python 3.6 #368

Merged
merged 7 commits into from
Jul 6, 2017

Conversation

DougBurke
Copy link
Contributor

@DougBurke DougBurke commented Jul 5, 2017

Release Note

Update the DS9 code so that external processes are cleaned up properly, so to remove the potential ResourceWarning warnings when running DS9 on Python 3.6.

Notes

Update the DS9 code so that external processes are cleaned up properly. This removes the ResourceWarning warnings raised when running the sherpa/image/tests/test_image.py test. The Travis python 3.6 build is no longer allowed to fail.

DougBurke and others added 5 commits July 5, 2017 16:43
This is primarily to stop the ResourceWarning warnings that are created
when running sherpa/image/tests/test_image.py under Python 3.6.

In all-but-one case this is a simple fix, with the code being converted
to use the context-manager approach to subprocess.Popen. These are
the calls to xpaset and xpaget. The remaining issue is running ds9,
which is meant to be run in the background: without explicitly using
os.fork - which is not available on Windows - it's not clear how best
to handle this so I have used a hack. It might be sensible to store
the Popen instance when calling ds9 and storing it in the DS9Win class,
but it's not clear if this helps this particular issue.
@DougBurke
Copy link
Contributor Author

This replaces PR #364. It removes the decorator and --show-warnings option.

@DougBurke
Copy link
Contributor Author

Should we update the python-support button in README.md to now say "2.7,3.5,3.6" (either as part of this PR or once this has landed)?

@olaurino olaurino requested review from olaurino and removed request for olaurino July 6, 2017 14:05
@olaurino
Copy link
Member

olaurino commented Jul 6, 2017

would the commit I added do?

@DougBurke
Copy link
Contributor Author

LGTM - you can see the badge at https://github.com/DougBurke/sherpa/blob/remove-ds9-warnings-with-py36/README.md

There's some other clean up needed in README.md, but I think it's more extensive than is warranted for this PR (e.g. there's mention of the latest release being 4.8.2), and should be done in a "Here's the documentation for the 4.9.1 release" PR).

@olaurino olaurino merged commit b5ce743 into sherpa:master Jul 6, 2017
@DougBurke DougBurke deleted the remove-ds9-warnings-with-py36 branch July 6, 2017 22:37
@olaurino
Copy link
Member

Unfortunately, this code does not work in Python 2, where Popen does not implement the context manager protocol. I am exploring some options, but maybe we should just revert this? The real problem is that we didn't pick up the issue from the CI jobs, so I am making sure we add a ds9 smoke test, and that we require ds9 in the CI jobs that install it as a dependency.

@DougBurke
Copy link
Contributor Author

I guess the

with Popen(...) as blah:
    moreblah()

could be changed to

blah = Popen(...)
try:
    moreblah()
finally:
    blah.<not sure exactly what methods to call here>()

but, as indicated, I'm not sure what needs to be explicitly closed.

Another option would be to add the ResourceWarning messages to conftest.py so that we can pass the tests with Python 3.6 (as these particular warnings are not "serious").

@DougBurke
Copy link
Contributor Author

Or there are some 2.7 solutions in https://stackoverflow.com/questions/30421003/exception-handling-when-using-pythons-subprocess-popen

I think we could define _Popen in Python pre 3.2 to have the necessary enter/exit methods to act as a context manager.

@DougBurke
Copy link
Contributor Author

With python 2.7 I get this:

% python -c 'import sherpa.astro.ui'
WARNING: imaging routines will not be available, 
failed to import sherpa.image.ds9_backend due to 
'AttributeError: __exit__'
WARNING: failed to import sherpa.astro.xspec; XSPEC models will not be available

as a quick check to see if it's still happening.

DougBurke added a commit to DougBurke/sherpa that referenced this pull request Jul 10, 2017
For Python versions prior to 3.2 add in explicit code to make _Popen
work as a context manager.
@DougBurke
Copy link
Contributor Author

See PR #373

olaurino pushed a commit to DougBurke/sherpa that referenced this pull request Jul 11, 2017
For Python versions prior to 3.2 add in explicit code to make _Popen
work as a context manager.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants