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 failure when patching builtins on python 3.7.7 (patched open() doesn't take keyword arguments) #683

Closed
timt8 opened this issue Jan 29, 2021 · 3 comments

Comments

@timt8
Copy link

timt8 commented Jan 29, 2021

Running python 3.7.7, and monkey patching builtins, I see the following exception when configuring logging.
Looks like the patched open() call should take in keyword args?

In setup logging
Traceback (most recent call last):
  File "/Users/tim/.pyenv/versions/3.7.7/lib/python3.7/logging/config.py", line 563, in configure
    handler = self.configure_handler(handlers[name])
  File "/Users/tim/.pyenv/versions/3.7.7/lib/python3.7/logging/config.py", line 736, in configure_handler
    result = factory(**kwargs)
  File "/Users/tim/.pyenv/versions/3.7.7/lib/python3.7/logging/handlers.py", line 148, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/Users/tim/.pyenv/versions/3.7.7/lib/python3.7/logging/handlers.py", line 55, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/Users/tim/.pyenv/versions/3.7.7/lib/python3.7/logging/__init__.py", line 1087, in __init__
    StreamHandler.__init__(self, self._open())
  File "/Users/tim/.pyenv/versions/3.7.7/lib/python3.7/logging/__init__.py", line 1116, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
TypeError: open() got an unexpected keyword argument 'encoding'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./test.py", line 46, in <module>
    setup_logging()
  File "./test.py", line 43, in setup_logging
    logging.config.dictConfig(logging_dict)
  File "/Users/tim/.pyenv/versions/3.7.7/lib/python3.7/logging/config.py", line 800, in dictConfig
    dictConfigClass(config).configure()
  File "/Users/tim/.pyenv/versions/3.7.7/lib/python3.7/logging/config.py", line 571, in configure
    '%r' % name) from e
ValueError: Unable to configure handler 'file'

Script used to reproduce:

#!/usr/bin/env python

import eventlet
eventlet.monkey_patch(os=True,
                      select=True,
                      socket=True,
                      thread=True,
                      psycopg=True,
                      time=True,
                      builtins=True)

import logging.config

logging_dict = {
    'version': 1,
    'loggers': {
            '': {
                'level': 'INFO',
               'handlers': ['file'],
               'propagate': False
            },
    },
    'handlers': {
            'file': {
                'class': 'logging.handlers.RotatingFileHandler',
                'level': 'INFO',
                'formatter': 'detailed',
                'filename': '/tmp/foo.log',
                'mode': 'a',
                'maxBytes': 10485760,
                'backupCount': 9,
           },
    },
    'formatters': {
            'detailed': {
                'format': '%(asctime)s [%(name)s|%(process)d|%(thread)d|%(threadName)s] | %(filename)s:%(funcName)s:(lineno)d (%(levelname)s) - %(message)s'  # noqa: E501
            }
    }
}

def setup_logging():
    print('In setup logging')
    logging.config.dictConfig(logging_dict)

if __name__ == "__main__":
    setup_logging()`
@temoto
Copy link
Member

temoto commented Jan 30, 2021

@timt8 fix is merged into master. Please, try again with latest code.

pip install https://github.com/eventlet/eventlet/archive/master.zip

@timt8
Copy link
Author

timt8 commented Jan 31, 2021

Thank you so much @temoto! Will this be included in an upcoming release? I may have missed it, but I don't think I saw the changes in the latest (0.30.0) release.

@timt8 timt8 closed this as completed Jan 31, 2021
@temoto
Copy link
Member

temoto commented Feb 2, 2021

@timt8 it's in v0.30.1

bors bot added a commit to duckinator/parts.horse that referenced this issue Feb 3, 2021
73: Update eventlet to 0.30.1 r=duckinator a=pyup-bot


This PR updates [eventlet](https://pypi.org/project/eventlet) from **0.30.0** to **0.30.1**.



<details>
  <summary>Changelog</summary>
  
  
   ### 0.30.1
   ```
   ======
* patcher: built-in open() did not accept kwargs eventlet/eventlet#683
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/eventlet
  - Changelog: https://pyup.io/changelogs/eventlet/
  - Homepage: http://eventlet.net
</details>



Co-authored-by: pyup-bot <github-bot@pyup.io>
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

2 participants