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

Fix logger pickling error #407

Merged
merged 4 commits into from
Apr 30, 2021
Merged
Changes from 1 commit
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
Next Next commit
Fix logger pickling error
  • Loading branch information
Derek-Wds committed Apr 29, 2021
commit f58c61a2e0c313074729da6715d30d58e1503e69
10 changes: 10 additions & 0 deletions qlib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __new__(cls, name, bases, dict):
wrapper_dict = logging.Logger.__dict__.copy()
wrapper_dict.update(dict)
wrapper_dict["__doc__"] = logging.Logger.__doc__
del wrapper_dict["__reduce__"] # make Logger object can be pickled
Derek-Wds marked this conversation as resolved.
Show resolved Hide resolved
return type.__new__(cls, name, bases, wrapper_dict)


Expand All @@ -29,6 +30,15 @@ def __init__(self, module_name):
self.module_name = module_name
self.level = 0

def __getstate__(self):
Derek-Wds marked this conversation as resolved.
Show resolved Hide resolved
return vars(self)

def __setstate__(self, state):
vars(self).update(state)

def __reduce__(self):
Derek-Wds marked this conversation as resolved.
Show resolved Hide resolved
return (QlibLogger, (self.module_name,))

@property
def logger(self):
logger = logging.getLogger(self.module_name)
Expand Down