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

Logging when python interpreter exits fails when it cannot import sys #14

Open
ankostis opened this issue Jun 27, 2017 · 1 comment
Open

Comments

@ankostis
Copy link

The first statement of RainbowLoggingHandler._emit() is: import sys statement.
Importing libraries when python shutsdown raises the following exception:

--- Logging error ---
Traceback (most recent call last):
  File "/python/lib/site_packages/rainbow_logging_handler/__init__.py", line 194, in emit
    msg = self._encode(msg)
  File "/python/lib/site_packages/rainbow_logging_handler/__init__.py", line 210, in _encode
    import sys
ImportError: sys.meta_path is None, Python is likely shutting down
Call stack:
  File "/python/app/foo.py", line 65, in __del__
    self.close()
  File "/python/lib/logging/__init__.py", line 1294, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/python/lib/logging/__init__.py", line 1442, in _log
    self.handle(record)
  File "/python/lib/logging/__init__.py", line 1452, in handle
    self.callHandlers(record)
  File "/python/lib/logging/__init__.py", line 1514, in callHandlers
    hdlr.handle(record)
  File "/python/lib/logging/__init__.py", line 863, in handle
    self.emit(record)
  File "/python/lib/site_packages/rainbow_logging_handler/__init__.py", line 200, in emit
    self.handleError(record)
Message: 'Closing somethid: %s'
Arguments: ('something')

Many libraries use logging statements just before python interpreter exits, e.g inside finalizers, and this causes an annoying cascade of log-failures at the exit of the application.

The solution is to move the import sys statement at the top of the rainbow_logging_handler/__init__.py file.

@ankostis
Copy link
Author

ankostis commented Aug 6, 2018

Any chance for a new release with this bug fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant