7

I'm using a basic logger to keep track in the terminal of what my program is doing and I've noticed that logs are sometimes delayed for a few seconds or minutes or even purely skipped for no reason.

Here is my logging setup:

import logging
logging.basicConfig(
  level=logging.WARNING,
  format='%(asctime)s %(name)s %(levelname)s %(message)s'
)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

Nothing fancy so, and here is a sample of code where I'm using the logger, here after a keypress event but the delays occurred before I decided to handle events:

    if event.key == "c":
        if self.mode != "clock":
            logger.info("switching to clock mode")
            self.mode = "clock"
            self.gravitons = []
            self.updateGravitonsKTree()
            self.canShuffle = False
    elif event.key == "f":
        if self.mode != "free":
            logger.info("switching to free mode")
            self.mode = "free"
            self.gravitons = []
            self.updateGravitonsKTree()
    (...)

I know for sure only the output of the logger is delayed or skipped because I can see the rest of the program is reacting normally and instantly so I guess there is a kind of buffer maybe which is not properly flushed but I saw nothing about this in the logging module's documentation.

Also in this program I'm using a matplotlib animation and I suspect it has something to do with this issue but I confess I have no clear understanding of why and how this could be the case.

Has someone ever experienced the same thing? And is there a way to "fix" it?

1
  • Facing similar problem, wondering if you could find any root cause/solution to the issue.
    – nom-mon-ir
    Commented Sep 10, 2020 at 18:33

0

Browse other questions tagged or ask your own question.