borgend/fifolog.py

Sun, 04 Feb 2018 01:36:59 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 04 Feb 2018 01:36:59 +0000
changeset 102
0d43cd568f3c
parent 89
51cc2e25af38
permissions
-rw-r--r--

Changed scheduler busylooping method, and decreased precision to 5 minutes:
if there are finite-horizon events in the queue, the scheduler thread will never
sleep longer than that. This is to quickly get back on track with the schedule
when the computer wakes up from sleep, if the sleep monitor is not working or
is not implemented for the particular operating system. However, if there are
only infinite-horizon events in the queue (meaning, DreamTime-scheduled events,
and the system is sleeping or "sleeping"), the scheduler will also sleep.
Hopefully this will also help the system stay properly asleep.

#
# Borgend by Tuomo Valkonen, 2018
#
# This is a simple limited memory FIFO log for the logging module
#

from logging.handlers import BufferingHandler

class FIFOHandler(BufferingHandler):
    def shouldFlush(self, record):
        return False

    def emit(self, record):
        self.buffer.append(record)
        l=len(self.buffer)
        if l>self.capacity:
            self.buffer=self.buffer[(l-self.capacity):(l-1)]

    def formatAll(self):
        return [self.format(record) for record in self.buffer]

mercurial