Skip to content
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
14 changes: 10 additions & 4 deletions pymodbus/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import asyncio
import dataclasses
import ssl
import sys
from contextlib import suppress
from enum import Enum
from typing import Any, Callable, Coroutine
Expand All @@ -14,6 +15,14 @@

NULLMODEM_HOST = "__pymodbus_nullmodem"

if sys.version_info.minor == 11:
USEEXCEPTIONS: tuple[type[Any], type[Any]] | type[Any] = OSError
else:
USEEXCEPTIONS = (
asyncio.TimeoutError,
OSError,
)


class CommType(Enum):
"""Type of transport"""
Expand Down Expand Up @@ -229,10 +238,7 @@ async def transport_connect(self) -> bool:
self.call_create(),
timeout=self.comm_params.timeout_connect,
)
except (
asyncio.TimeoutError,
OSError,
) as exc:
except USEEXCEPTIONS as exc:
Log.warning("Failed to connect {}", exc)
self.transport_close(intern=True, reconnect=True)
return False
Expand Down