Да, он выполняет сброс вывода при каждом вызове. Вы можете увидеть это в исходном коде для StreamHandler
:
def flush(self):
"""
Flushes the stream.
"""
self.acquire()
try:
if self.stream and hasattr(self.stream, "flush"):
self.stream.flush()
finally:
self.release()
def emit(self, record):
"""
Emit a record.
If a formatter is specified, it is used to format the record.
The record is then written to the stream with a trailing newline. If
exception information is present, it is formatted using
traceback.print_exception and appended to the stream. If the stream
has an 'encoding' attribute, it is used to determine how to do the
output to the stream.
"""
try:
msg = self.format(record)
stream = self.stream
stream.write(msg)
stream.write(self.terminator)
self.flush() # <---
except (KeyboardInterrupt, SystemExit): #pragma: no cover
raise
except:
self.handleError(record)
Я не возражаю о выполнении рубок, по крайней мере, до профилирования и обнаружить, что это является узким местом. В любом случае вы всегда можете создать подкласс Handler
, который не выполняет flush
при каждом вызове emit
(даже если вы рискуете потерять много журналов, если возникает плохое исключение/сбой интерпретатора).
Не метод 'flush()', исходящий из класса [предка] (https://docs.python.org/2/library/logging.handlers.html#module-logging.handlers) с пустым телом? Метод 'flush()' для 'StreamHandler()' переопределяет его? – akhan
@akhan [Да.] (Https://hg.python.org/cpython/file/3.5/Lib/logging/__init__.py#l958) – Bakuriu