TypeError: can't pickle _thread.RLock objects
NejcKozjekKnaufInsulation opened this issue · comments
Your module works perfectly fine on macos, but I can't get it to work on Windows. The source is identical.
I am on python 3.6.8 and concurrent-log-handler 0.9.16
In essence, what I'm doing is I am defining a logger on top level and use it in a class method executed with concurrent_futures.ProcessPoolExecutor:
class Foo():
...
def func(self):
logger.info("logthis")
def get_logger(loggerFilename)
logger = logging.getLogger()
rotateHandler = ConcurrentRotatingFileHandler(loggerFilename, "a", 512*1024, 100)
# format of the log
formatter = logging.Formatter("%(asctime)s %(process)d %(funcName)16s %(levelname)8s %(message)s")
rotateHandler.setFormatter(formatter)
logger.addHandler(rotateHandler)
# mode of the log
logger.setLevel(logging.INFO)
return logger
if __name__ == "__main__":
loggerFilename = "/path/to/log"
logger = get_logger(loggerFilename)
c1 = Foo()
c2 = Foo()
with ProcessPoolExecutor(max_workers=6) as executor:
executor.submit(c1.func)
executor.submit(c2.func)
Return with error pickling error: TypeError: can't pickle _thread.RLock objects.
Any help would be appreciated.
Can you submit a complete sample program that demonstrates this? Also include the full traceback you're getting.
I took a slightly modified version of your code and was able to run it successfully on Windows Python 3.7.3:
https://gist.github.com/Preston-Landers/4a7868e465499f7fc99186ab10ad803c
The only significant change was the call to get_logger is NOT inside the "if name == main" section.
Initialising logger outside of main solved my issue. Appreciate the help and all your wonderful work on this package. Thank you!
Glad to hear it. Thanks!