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

ResourceWarnings in py3 during test #86

Closed
KSchopmeyer opened this issue Mar 12, 2016 · 15 comments · Fixed by #2497, #2488 or #2496
Closed

ResourceWarnings in py3 during test #86

KSchopmeyer opened this issue Mar 12, 2016 · 15 comments · Fixed by #2497, #2488 or #2496

Comments

@KSchopmeyer
Copy link
Collaborator

KSchopmeyer commented Mar 12, 2016

While probably not critical, there is no way I could see to disconnect a connection when finished.

Andy: Generalized the issue from ResourceWarnings about open sockets / WBEMConnection has no close() to cover all ResourceWarnings during test.

@andy-maier
Copy link
Contributor

Because the connection is only conceptual, it does not need to be closed. The WBEMConnection object will be garbage collected once unused, but that does not matter for that.

@KSchopmeyer
Copy link
Collaborator Author

Note that with python 3, the run_cim_operations.py test repeatedly reports:

timeout=self.timeout)
/home/kschopmeyer/pywbem/githubpywbem/pywbem/pywbem/cim_operations.py:596: ResourceWarning: unclosed <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.3.138', 59717), raddr=('192.168.3.138', 5988)>
timeout=self.timeout)

Which is where I figured out that there was no timeout.

@KSchopmeyer
Copy link
Collaborator Author

In retrospect this may be a more serious problem than I originally thought but not sure yet.

Note that we are running tests with timeout = 0 at this point

@andy-maier
Copy link
Contributor

Ok. The discussion in this issue of the requests package: https://github.com/kennethreitz/requests/issues/1882 seems to say that the warning is not an issue, but it remains unclear why it is being raised.

I don't think we want to explicitly destroy the socket after each CIM operation; that would be an efficiency problem.

Maybe you are right and an explicit close() on the WBEMConnection object would be a solution to avoid the warning. But we need to investigate what we would do in such a close() method.

@KSchopmeyer
Copy link
Collaborator Author

Most other platforms have a close and that seems logical. I agree. This is really a 0.9.0 issue and should not be 0.8.0

@andy-maier
Copy link
Contributor

Moving to 0.9.0.

@andy-maier andy-maier modified the milestones: 0.9.0, 0.8.0 Mar 15, 2016
@andy-maier andy-maier removed their assignment Mar 21, 2016
@KSchopmeyer KSchopmeyer self-assigned this Mar 24, 2016
@KSchopmeyer KSchopmeyer removed this from the 0.9.0 milestone Apr 6, 2016
@andy-maier
Copy link
Contributor

Discussion point: The requests package is able to maintain a socket pool and handle socket reuse automatically. Because we want to use that package, I don't think that we need a close() method on WBEMConnection.

@andy-maier andy-maier added this to the 0.10.0 milestone Sep 6, 2016
@KSchopmeyer KSchopmeyer removed this from the 0.10.0 milestone Sep 7, 2016
@KSchopmeyer
Copy link
Collaborator Author

What we do here depends on the package we use in the future. If we go to requests, Andy's point above is correct. Left open until we pick next ssl/ http package to work with

@andy-maier
Copy link
Contributor

This issue waits for the decision to move or not to move to using the requests package (see issue #280).

@andy-maier
Copy link
Contributor

This issue needs to be re-evaluated with the current master version (which is based on the requests package).

@andy-maier
Copy link
Contributor

andy-maier commented Jul 17, 2020

The current master branch (close to 1.0.0 final) shows the following ResourceWarnings during test, on Python 3.8 with latest package levels.

They are all about unclosed files; the earlier open sockets warnings are gone since we moved to use 'requests'.

$ py.test --color=yes --cov pywbem --cov pywbem_mock  --cov-config coveragerc -W default -W ignore::PendingDeprecationWarning  tests/unittest tests/functiontest -s

. . . (reduced to just ResourceWarning):

tests/unittest/pywbem/test_cim_obj.py: 1431 tests with warnings
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/utils/validate.py:186:
   ResourceWarning: unclosed file <_io.BufferedReader name=6>
    validate_cim_xml(obj_xml_str, root_elem_name)

tests/unittest/pywbem/test_cim_xml.py: 183 tests with warnings
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_cim_xml.py:4261:
   ResourceWarning: unclosed file <_io.BufferedReader name=6>
    validate_cim_xml(act_xml_str)

tests/unittest/pywbem/test_logging.py: 12 tests with warnings
  /Users/maiera/PycharmProjects/pywbem/pywbem/pywbem/_cim_operations.py:1442:
   ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log' mode='a' encoding='UTF-8'>
    cls._activate_logger(logger_name, simple_name, detail_level, handler,

tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-api]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-http]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-all]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-api]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-http]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-all]
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.py:151:
   ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log' mode='a' encoding='UTF-8'>
    configure_logger(log_name, log_dest=log_dest,

tests/unittest/pywbem/test_mof_compiler.py::TestRemove::test_remove
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_mof_compiler.py:331:
   ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/moflog.txt' mode='w' encoding='UTF-8'>
    self.logfile = open(moflog_file, 'w')

tests/unittest/pywbem/test_mof_compiler.py::TestSchemaSearch::test_search_None
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_mof_compiler.py:655:
   ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/moflog.txt' mode='w' encoding='UTF-8'>
    open(moflog_file, 'w')

tests/unittest/pywbem/test_mof_compiler.py::TestSchemaSearch::test_search_single_string
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_mof_compiler.py:627:
   ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/moflog.txt' mode='w' encoding='UTF-8'>
    open(moflog_file, 'w')

tests/unittest/pywbem/test_mof_compiler.py::TestPartialSchema::test_build_from_schema_string
  /Users/maiera/virtualenvs/pywbem38/lib/python3.8/site-packages/ply/lex.py:325:
   ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/moflog2.txt' mode='w' encoding='UTF-8'>
    tok = LexToken()

@andy-maier andy-maier changed the title ResourceWarning in py3 about open sockets / WBEMConnection has no close() ResourceWarnings in py3 Jul 17, 2020
@andy-maier andy-maier changed the title ResourceWarnings in py3 ResourceWarnings in py3 during test Jul 17, 2020
@andy-maier andy-maier removed this from the 1.1.0 milestone Aug 19, 2020
@andy-maier andy-maier added this to the 1.2.0 milestone Oct 7, 2020
@andy-maier
Copy link
Contributor

PR #2488 fixed a ResourceWarning for not closing a MOF log file.

With the current master, we still have the following ResourceWarnings:

$ py.test --color=yes --cov pywbem --cov pywbem_mock  --cov-config coveragerc -W default -W ignore::PendingDeprecationWarning tests/unittest tests/functiontest -s

tests/unittest/pywbem/test_logging.py: 12 tests with warnings
  /Users/maiera/PycharmProjects/pywbem/pywbem/pywbem/_cim_operations.py:1431: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log' mode='a' encoding='UTF-8'>
    cls._activate_logger(logger_name, simple_name, detail_level, handler,

tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-api]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-http]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-all]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-api]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-http]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-all]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-detail_level14-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-api]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-detail_level14-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-http]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-detail_level14-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-all]
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.py:154: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log' mode='a' encoding='UTF-8'>
    configure_logger(log_name, log_dest=log_dest,

tests/unittest/pywbem/test_mof_compiler.py::TestRemove::test_remove
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_mof_compiler.py:351: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/moflog.txt' mode='w' encoding='UTF-8'>
    self.logfile = open(moflog_file, 'w')

tests/unittest/pywbem/test_mof_compiler.py::TestSchemaSearch::test_search_None
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_mof_compiler.py:675: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/moflog.txt' mode='w' encoding='UTF-8'>
    open(moflog_file, 'w')

tests/unittest/pywbem/test_mof_compiler.py::TestSchemaSearch::test_search_single_string
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_mof_compiler.py:647: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/moflog.txt' mode='w' encoding='UTF-8'>
    open(moflog_file, 'w')

@andy-maier
Copy link
Contributor

andy-maier commented Oct 10, 2020

PR #2496 fixes the ResourceWarning for the test_mof_compiler.py cases.

That leaves the following cases, all related to logging:

$ py.test --color=yes --cov pywbem --cov pywbem_mock  --cov-config coveragerc -W default -W ignore::PendingDeprecationWarning tests/unittest tests/functiontest -s

tests/unittest/pywbem/test_logging.py: 12 tests with warnings
  /Users/maiera/PycharmProjects/pywbem/pywbem/pywbem/_cim_operations.py:1431: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log' mode='a' encoding='UTF-8'>
    cls._activate_logger(logger_name, simple_name, detail_level, handler,

tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-api]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-http]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-blah-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-all]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-api]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-http]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file--9-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-all]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-detail_level14-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-api]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-detail_level14-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-http]
tests/unittest/pywbem/test_logging.py::TestLoggingConfigure::test_configure_logger[file-detail_level14-/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log-ValueError-all]
  /Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.py:154: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/maiera/PycharmProjects/pywbem/pywbem/tests/unittest/pywbem/test_logging.log' mode='a' encoding='UTF-8'>
    configure_logger(log_name, log_dest=log_dest,

Fixing the cases related to logging requires some thought:

  • The logger object is global, but the control about logging can be global and specific to each connection. So if we stay with this approach, it requires an awareness of that.
  • Should we stay with one global logger or change to add logger objects per connection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment