diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-11-11 20:22:39 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-11-12 22:53:43 -0500 |
commit | 1dee1ba64e52394446e8aa67a8418f066257a9a2 (patch) | |
tree | ede2123e397183bb68a7f25c907ee751d138c513 /klippy/klippy.py | |
parent | afecf7ce36d4d712413d8c90ac055baa51cb26bd (diff) | |
download | kutter-1dee1ba64e52394446e8aa67a8418f066257a9a2.tar.gz kutter-1dee1ba64e52394446e8aa67a8418f066257a9a2.tar.xz kutter-1dee1ba64e52394446e8aa67a8418f066257a9a2.zip |
queuelogger: Add support for background log writing
Writing to the debug log can cause an unbounded delay due to disk IO.
This is particularly so on embedded machines such as the Raspberry Pi
that run on SD cards. These log writing delays can cause problems for
the main processing threads.
The new "queuelogger" code forwards all the main thread log messages
to a queue, and a background thread writes the log messages from the
queue to the destination file. This eliminates the IO delay from the
main threads.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r-- | klippy/klippy.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/klippy/klippy.py b/klippy/klippy.py index cb81364e..6668ef4c 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -5,7 +5,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import sys, optparse, ConfigParser, logging, time, threading -import gcode, toolhead, util, mcu, fan, heater, extruder, reactor +import gcode, toolhead, util, mcu, fan, heater, extruder, reactor, queuelogger class ConfigWrapper: def __init__(self, printer, section): @@ -132,7 +132,7 @@ def main(): opts.error("Incorrect number of arguments") conffile = args[0] - debuginput = debugoutput = None + debuginput = debugoutput = bglogger = None debuglevel = logging.INFO if options.verbose: @@ -142,8 +142,7 @@ def main(): if options.outputfile: debugoutput = open(options.outputfile, 'wb') if options.logfile: - logoutput = open(options.logfile, 'wb') - logging.basicConfig(stream=logoutput, level=debuglevel) + bglogger = queuelogger.setup_bg_logging(options.logfile, debuglevel) else: logging.basicConfig(level=debuglevel) logging.info("Starting Klippy...") @@ -159,5 +158,8 @@ def main(): store_dictionary(options.write_dictionary, printer) printer.run() + if bglogger is not None: + bglogger.stop() + if __name__ == '__main__': main() |