[elbe-devel] [PATCH 5/5] elbepack: log: work around multiprocessing bug

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Oct 2 12:09:48 CEST 2024


Old versions of Python have a bug that is triggered by our usage of the
multiprocessing module.
This bug is already fixed but the version of Python in Debian bullseye
does not and will not contain this patch.

Work around this by monkeypatching the affected stdlib function.
While is is obviously a hack it should be fine as it only replicates an
actually released bugfix.
While the value of 'manager_owned' should be passed through instead of
discarded, this seems to work well enough for the usecase in elbe.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/log.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/elbepack/log.py b/elbepack/log.py
index 7d8f66ee93c3c28a6e3b06bf5b0484060f54b48c..ef7eb5a5d9fb4cee3570a4ad46d7d64b7e40d231 100644
--- a/elbepack/log.py
+++ b/elbepack/log.py
@@ -4,11 +4,13 @@
 
 
 import collections
+import functools
 import logging
 import multiprocessing
 import multiprocessing.managers
 import os
 import re
+import sys
 import threading
 from contextlib import contextmanager
 
@@ -22,6 +24,22 @@ report = logging.getLogger('report')
 validation = logging.getLogger('validation')
 
 
+def _swallow_kwargs(func, *names):
+    @functools.wraps(func)
+    def _wrapper(*args, **kwargs):
+        for name in names:
+            kwargs.pop(name, None)
+        return func(*args, **kwargs)
+
+    return _wrapper
+
+
+if sys.version_info < (3, 9, 7) and hasattr(multiprocessing.managers, 'AutoProxy'):
+    # See https://bugs.python.org/issue30256 and linked issues
+    multiprocessing.managers.AutoProxy = _swallow_kwargs(
+            multiprocessing.managers.AutoProxy, 'manager_owned')
+
+
 class LoggingQueue(collections.deque):
     def __init__(self):
         super().__init__(maxlen=1024)

-- 
2.46.2



More information about the elbe-devel mailing list