Antoine Pitrou added the comment: Le 01/06/2017 à 09:14, Vinay Sajip a écrit : > > I am not sure it is a good idea to support pickling of loggers, as they are > singletons and generally aren't supposed to be instantiated other than by > calling logging.getLogger(name).
Pickling them by name is precisely what I'm having in mind. Right now, pickle tries to recreate them structurally, which fails. In other words (untested, but you get the idea): class Logger: def __reduce__(self): return getLogger, (self.name,) > What's the use case for pickling them, You usually don't pickle loggers directly. You pickle an object that happens to hold (directly or indirectly) a reference to a logger (it's quite common to have `self.logger = ...` in your code), and pickle tries to pickle the logger as part of pickling that object. > One could implement __getstate__() to just return the name, but there is no corresponding obvious implementation of __setstate__() because loggers aren't meant to be instantiated via unpickling. No need for __getstate__ or __setstate__, __reduce__ should work fine (see above). ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30520> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com