aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-12-17 09:51:45 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-12-17 09:51:45 -0500
commitabf493496c5857cb504c69fe771801781865e5db (patch)
tree13a1ff3056b904cf811fe7423c774ea9b7dd0be1
parentd9cd524aec5c9d88de35e0c4b33de2fbd10a12a8 (diff)
downloadkutter-abf493496c5857cb504c69fe771801781865e5db.tar.gz
kutter-abf493496c5857cb504c69fe771801781865e5db.tar.xz
kutter-abf493496c5857cb504c69fe771801781865e5db.zip
mathutil: Disable queuelogger in background_coordinate_descent()
If the queuelogger was holding the lock when the process is forked then any attempt to log from the background process would result in a deadlock. Attempt a workaround by disabling the queuelogger at the start of the background process. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/mathutil.py4
-rw-r--r--klippy/queuelogger.py17
2 files changed, 17 insertions, 4 deletions
diff --git a/klippy/mathutil.py b/klippy/mathutil.py
index 82f12b9c..a6ab50d2 100644
--- a/klippy/mathutil.py
+++ b/klippy/mathutil.py
@@ -1,9 +1,10 @@
# Simple math helper functions
#
-# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging, multiprocessing, traceback
+import queuelogger
######################################################################
@@ -51,6 +52,7 @@ def coordinate_descent(adj_params, params, error_func):
def background_coordinate_descent(printer, adj_params, params, error_func):
parent_conn, child_conn = multiprocessing.Pipe()
def wrapper():
+ queuelogger.clear_bg_logging()
try:
res = coordinate_descent(adj_params, params, error_func)
except:
diff --git a/klippy/queuelogger.py b/klippy/queuelogger.py
index 370b46e9..52a05261 100644
--- a/klippy/queuelogger.py
+++ b/klippy/queuelogger.py
@@ -1,6 +1,6 @@
# Code to implement asynchronous logging from a background thread
#
-# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, logging.handlers, threading, Queue, time
@@ -52,10 +52,21 @@ class QueueListener(logging.handlers.TimedRotatingFileHandler):
self.emit(logging.makeLogRecord(
{'msg': "\n".join(lines), 'level': logging.INFO}))
+MainQueueHandler = None
+
def setup_bg_logging(filename, debuglevel):
+ global MainQueueHandler
ql = QueueListener(filename)
- qh = QueueHandler(ql.bg_queue)
+ MainQueueHandler = QueueHandler(ql.bg_queue)
root = logging.getLogger()
- root.addHandler(qh)
+ root.addHandler(MainQueueHandler)
root.setLevel(debuglevel)
return ql
+
+def clear_bg_logging():
+ global MainQueueHandler
+ if MainQueueHandler is not None:
+ root = logging.getLogger()
+ root.removeHandler(MainQueueHandler)
+ root.setLevel(logging.WARNING)
+ MainQueueHandler = None