Skip to content

Commit ff200cf

Browse files
Address review: add sleep on OSError and improve docstrings in RX loops
Co-authored-by: pavel-kirienko <3298404+pavel-kirienko@users.noreply.github.com>
1 parent 2c731d6 commit ff200cf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/pycyphal/udp.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def close(self) -> None:
625625
# -- Internal async RX loops --
626626

627627
async def _mcast_rx_loop(self, sock: socket.socket, subject_id: int, iface_idx: int) -> None:
628-
"""Async loop that reads from a multicast socket and processes datagrams."""
628+
"""Async receive loop for a multicast socket. Runs until cancelled or transport is closed."""
629629
try:
630630
while not self._closed:
631631
try:
@@ -634,6 +634,7 @@ async def _mcast_rx_loop(self, sock: socket.socket, subject_id: int, iface_idx:
634634
if self._closed:
635635
break
636636
_logger.debug("Multicast recv error on subject %d iface %d", subject_id, iface_idx)
637+
await asyncio.sleep(0.1)
637638
continue
638639
src_ip, src_port = addr[0], addr[1]
639640
if (src_ip, src_port) in self._self_endpoints:
@@ -643,7 +644,7 @@ async def _mcast_rx_loop(self, sock: socket.socket, subject_id: int, iface_idx:
643644
pass
644645

645646
async def _unicast_rx_loop(self, sock: socket.socket, iface_idx: int) -> None:
646-
"""Async loop that reads from a unicast socket and processes datagrams."""
647+
"""Async receive loop for a unicast socket. Runs until cancelled or transport is closed."""
647648
try:
648649
while not self._closed:
649650
try:
@@ -652,6 +653,7 @@ async def _unicast_rx_loop(self, sock: socket.socket, iface_idx: int) -> None:
652653
if self._closed:
653654
break
654655
_logger.debug("Unicast recv error on iface %d", iface_idx)
656+
await asyncio.sleep(0.1)
655657
continue
656658
src_ip, src_port = addr[0], addr[1]
657659
if len(data) < HEADER_SIZE:

0 commit comments

Comments
 (0)