diff --git a/pymodbus/transaction/transaction.py b/pymodbus/transaction/transaction.py index 7a268c029..9d58a9857 100644 --- a/pymodbus/transaction/transaction.py +++ b/pymodbus/transaction/transaction.py @@ -224,11 +224,6 @@ async def execute( return response except asyncio.exceptions.TimeoutError: count_retries += 1 - except asyncio.exceptions.CancelledError as exc: - raise self._io_exception_from_request( - "Request cancelled outside library.", - request, - ) from exc if self.count_until_disconnect < 0: self.connection_lost(asyncio.TimeoutError("Server not responding")) raise self._io_exception_from_request( diff --git a/test/transaction/test_transaction.py b/test/transaction/test_transaction.py index 03f05497c..66b9ed4d4 100755 --- a/test/transaction/test_transaction.py +++ b/test/transaction/test_transaction.py @@ -247,10 +247,9 @@ async def test_transaction_execute(self, use_clc, scenario): await asyncio.sleep(0.1) resp.cancel() await asyncio.sleep(0.1) - with pytest.raises(ModbusIOException) as exc_info: + with pytest.raises(asyncio.CancelledError): await resp - assert exc_info.value.fcode == request.function_code - assert exc_info.value.dev_id == request.dev_id + assert resp.cancelled() elif scenario == 7: # response transact.comm_params.timeout_connect = 0.2 resp = asyncio.create_task(transact.execute(False, request))