How to pickle loggers?

后端 未结 5 1924
粉色の甜心
粉色の甜心 2021-02-14 22:17

Working on a project that requires that I am able to pickle the container object at any point, since we expect it to fail on external conditions quite frequently and be able to

5条回答
  •  无人共我
    2021-02-14 22:36

    You could have used dill here, which can pickle loggers and locks.

    >>> class foo:
    ...    def __init__(self):
    ...        self.logger = logging.getLogger("package.foo")
    ... 
    >>> import dill
    >>> import logging
    >>> 
    >>> f = foo()
    >>> _f = dill.dumps(f)  
    >>> f_ = dill.loads(_f)
    >>> f_.logger
    
    

提交回复
热议问题