|
16 | 16 | import warnings |
17 | 17 | from enum import Enum |
18 | 18 | from logging import getLogger |
19 | | -from threading import Lock, Timer |
| 19 | +from threading import Lock |
20 | 20 | from types import TracebackType |
21 | 21 | from typing import ( |
22 | 22 | IO, |
|
39 | 39 |
|
40 | 40 | from . import compat |
41 | 41 | from ._sql_util import get_file_transfer_type |
| 42 | +from ._utils import _TrackedQueryCancellationTimer |
42 | 43 | from .bind_upload_agent import BindUploadAgent, BindUploadError |
43 | 44 | from .constants import ( |
44 | 45 | FIELD_NAME_TO_ID, |
@@ -392,7 +393,9 @@ def __init__( |
392 | 393 | self.messages: list[ |
393 | 394 | tuple[type[Error] | type[Exception], dict[str, str | bool]] |
394 | 395 | ] = [] |
395 | | - self._timebomb: Timer | None = None # must be here for abort_exit method |
| 396 | + self._timebomb: _TrackedQueryCancellationTimer | None = ( |
| 397 | + None # must be here for abort_exit method |
| 398 | + ) |
396 | 399 | self._description: list[ResultMetadataV2] | None = None |
397 | 400 | self._sfqid: str | None = None |
398 | 401 | self._sqlstate = None |
@@ -654,7 +657,9 @@ def _execute_helper( |
654 | 657 | ) |
655 | 658 |
|
656 | 659 | if real_timeout is not None: |
657 | | - self._timebomb = Timer(real_timeout, self.__cancel_query, [query]) |
| 660 | + self._timebomb = _TrackedQueryCancellationTimer( |
| 661 | + real_timeout, self.__cancel_query, [query] |
| 662 | + ) |
658 | 663 | self._timebomb.start() |
659 | 664 | logger.debug("started timebomb in %ss", real_timeout) |
660 | 665 | else: |
@@ -1071,6 +1076,11 @@ def execute( |
1071 | 1076 | logger.debug(ret) |
1072 | 1077 | err = ret["message"] |
1073 | 1078 | code = ret.get("code", -1) |
| 1079 | + if self._timebomb and self._timebomb.executed: |
| 1080 | + err = ( |
| 1081 | + f"SQL execution was cancelled by the client due to a timeout. " |
| 1082 | + f"Error message received from the server: {err}" |
| 1083 | + ) |
1074 | 1084 | if "data" in ret: |
1075 | 1085 | err += ret["data"].get("errorMessage", "") |
1076 | 1086 | errvalue = { |
|
0 commit comments