backtrader.utils.flushfile module

Flush File Module - Auto-flushing file wrapper for Windows.

This module provides a wrapper for file-like objects that automatically flushes after each write. On Windows platforms, it replaces sys.stdout and sys.stderr with auto-flushing versions to ensure immediate output.

Classes:

flushfile: Wrapper that auto-flushes after each write. StdOutDevNull: Null output device that suppresses stdout.

备注

This is primarily for Windows compatibility where output buffering can cause delayed display of stdout/stderr.

class backtrader.utils.flushfile.flushfile[源代码]

基类:object

File wrapper that auto-flushes after each write.

This class wraps a file-like object and ensures that each write operation is immediately flushed to the underlying file descriptor.

f

The underlying file-like object.

备注

On Windows, this module automatically wraps sys.stdout and sys.stderr with flushfile instances.

__init__(f)[源代码]

Initialize the flushfile wrapper.

参数:

f -- File-like object to wrap (typically sys.stdout or sys.stderr).

write(x)[源代码]

Write data to the file and immediately flush.

参数:

x -- Data to write to the file.

flush()[源代码]

Flush the underlying file buffer.

class backtrader.utils.flushfile.StdOutDevNull[源代码]

基类:object

Null output device that suppresses stdout.

When active, all writes to stdout are discarded. The original stdout can be restored by calling the stop() method.

stdout

The original sys.stdout saved for restoration.

__init__()[源代码]

Initialize StdOutDevNull and replace sys.stdout.

write(x)[源代码]

Discard written data instead of outputting.

参数:

x -- Data to discard.

flush()[源代码]

No-op flush method for compatibility.

stop()[源代码]

Restore the original sys.stdout.