Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnect stream writer without closing the transport #58

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions universal_silabs_flasher/xmodemcrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
BLOCK_SIZE = 128
RECEIVE_TIMEOUT = 2

_WRITER_GRAVEYARD: list[asyncio.StreamWriter] = []


class PacketType(zigpy.types.enum8):
"""XModem packet type byte."""
Expand Down Expand Up @@ -144,6 +146,16 @@ async def send_xmodem128_crc(
max_failures=max_failures,
)
finally:
# XXX: Make sure the writer doesn't close our transport when garbage collected
global _WRITER_GRAVEYARD

_WRITER_GRAVEYARD.append(writer)
_WRITER_GRAVEYARD = [
w
for w in _WRITER_GRAVEYARD
if w.transport is not None and not w.transport.is_closing()
]

# Reset the old protocol
transport.set_protocol(old_protocol)

Expand Down
Loading