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

BUG: pickle RootLogger object #160

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,11 @@ def save_logger(self, obj):

dispatch[logging.Logger] = save_logger

def save_root_logger(self, obj):
self.save_reduce(logging.getLogger, (), obj=obj)

dispatch[logging.RootLogger] = save_root_logger
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since logging.RootLogger derives from logging.Logger I was wondering whether it would be worth to walk the class __mro__ in order to find a custom reduce function. I went for the simpler option.


"""Special functions for Add-on libraries"""
def inject_addons(self):
"""Plug in system. Register additional pickling functions if modules already loaded"""
Expand Down
12 changes: 9 additions & 3 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ def test_cell_manipulation(self):
msg='cell contents not set correctly',
)

def test_logger(self):
logger = logging.getLogger('cloudpickle.dummy_test_logger')
def check_logger(self, name):
Copy link
Contributor Author

@lesteve lesteve Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use pytest.mark.parametrize but I could not make it work with test classes deriving from unittest.TestCase (see this SO answer which seems to indicate that this is not possible)

logger = logging.getLogger(name)
pickled = pickle_depickle(logger, protocol=self.protocol)
self.assertTrue(pickled is logger, (pickled, logger))

Expand All @@ -633,7 +633,13 @@ def test_logger(self):
out, _ = proc.communicate()
self.assertEqual(proc.wait(), 0)
self.assertEqual(out.strip().decode(),
'INFO:cloudpickle.dummy_test_logger:hello')
'INFO:{}:hello'.format(logger.name))

def test_logger(self):
# logging.RootLogger object
self.check_logger(None)
# logging.Logger object
self.check_logger('cloudpickle.dummy_test_logger')

def test_abc(self):

Expand Down