Skip to content

Commit

Permalink
Fix performance regression in debug logging from win32 protobuf crash…
Browse files Browse the repository at this point in the history
… workaround (#940)
  • Loading branch information
bdraco authored Aug 29, 2024
1 parent 059af0e commit fce8922
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions aioesphomeapi/connection.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cdef float KEEP_ALIVE_TIMEOUT_RATIO
cdef object HANDSHAKE_TIMEOUT

cdef bint TYPE_CHECKING
cdef bint _WIN32

cdef object WRITE_EXCEPTIONS

Expand Down
5 changes: 3 additions & 2 deletions aioesphomeapi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@

WRITE_EXCEPTIONS = (RuntimeError, ConnectionResetError, OSError)

_WIN32 = sys.platform == "win32"

_int = int
_bytes = bytes
Expand Down Expand Up @@ -719,7 +720,7 @@ def send_messages(self, msgs: tuple[message.Message, ...]) -> None:
# calling __str__ on the message may crash on
# Windows systems due to a bug in the protobuf library
# so we call MessageToDict instead
MessageToDict(msg),
MessageToDict(msg) if _WIN32 else msg,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -921,7 +922,7 @@ def process_packet(self, msg_type_proto: _int, data: _bytes) -> None:
# calling __str__ on the message may crash on
# Windows systems due to a bug in the protobuf library
# so we call MessageToDict instead
MessageToDict(msg),
MessageToDict(msg) if _WIN32 else msg,
)

if self._pong_timer is not None:
Expand Down

0 comments on commit fce8922

Please sign in to comment.