Skip to content

Commit 3cda7e5

Browse files
committed
add wait to thread join
1 parent dede881 commit 3cda7e5

File tree

6 files changed

+15
-4
lines changed

6 files changed

+15
-4
lines changed

aws_advanced_python_wrapper/driver_dialect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class DriverDialect(ABC):
4444
_read_only: bool = False
4545
_autocommit: bool = False
4646
_driver_name: str = "Generic"
47+
_query: str = "SELECT 1"
4748

4849
def __init__(self, props: Properties):
4950
self._props = props
@@ -156,7 +157,7 @@ def transfer_session_state(self, from_conn: Connection, to_conn: Connection):
156157
def ping(self, conn: Connection) -> bool:
157158
try:
158159
with conn.cursor() as cursor:
159-
query = "SELECT 1"
160+
query = _QUERY
160161
self.execute("Cursor.execute", lambda: cursor.execute(query), query, exec_timeout=10)
161162
cursor.fetchone()
162163
return True

aws_advanced_python_wrapper/fastest_response_strategy_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def is_stopped(self):
208208

209209
def close(self):
210210
self._is_stopped.set()
211-
self._daemon_thread.join()
211+
self._daemon_thread.join(5)
212212
logger.debug("HostResponseTimeMonitor.Stopped", self._host_info.host)
213213

214214
def _get_current_time(self):

aws_advanced_python_wrapper/host_monitoring_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ class Monitor:
349349
_INACTIVE_SLEEP_MS = 100
350350
_MIN_HOST_CHECK_TIMEOUT_MS = 3000
351351
_MONITORING_PROPERTY_PREFIX = "monitoring-"
352+
_QUERY: str = "SELECT 1"
352353

353354
def __init__(
354355
self,
@@ -560,7 +561,7 @@ def _is_host_available(self, conn: Connection, timeout_sec: float) -> bool:
560561
def _execute_conn_check(self, conn: Connection, timeout_sec: float):
561562
driver_dialect = self._plugin_service.driver_dialect
562563
with conn.cursor() as cursor:
563-
query = "SELECT 1"
564+
query = _query
564565
driver_dialect.execute("Cursor.execute", lambda: cursor.execute(query), query, exec_timeout=timeout_sec)
565566
cursor.fetchone()
566567

aws_advanced_python_wrapper/resources/aws_advanced_python_wrapper_messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ FailoverPlugin.UnableToConnectToReader=[Failover] Unable to establish SQL connec
9696
FailoverPlugin.UnableToConnectToWriter=[Failover] Unable to establish SQL connection to the writer instance.
9797

9898
FastestResponseStrategyPlugin.RandomHostSelected=[FastestResponseStrategyPlugin] Fastest host not calculated. Random host selected instead.
99-
FastestResponseStrategyPlugin.UnsupportedHostSelectorStrategy=[FastestResponseStrategyPlugin] Unsupported host selector strategy: `{}`. To use the fastest response strategy plugin, please ensure the property `reader_host_selector_strategy` is set to `fastest_response`
99+
FastestResponseStrategyPlugin.UnsupportedHostSelectorStrategy=[FastestResponseStrategyPlugin] Unsupported host selector strategy: '{}'. To use the fastest response strategy plugin, please ensure the property reader_host_selector_strategy is set to fastest_response.
100100

101101
FederatedAuthPlugin.UnhandledException=[FederatedAuthPlugin] Unhandled exception: '{}'
102102

docs/examples/MySQLFastestResponseStrategy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
conn.read_only = True
4343
with conn.cursor() as cursor_1:
4444
cursor_1.execute("SELECT * FROM bank_test")
45+
results = cursor_1.fetchall()
46+
for record in results:
47+
print(record)
4548

4649
# Switch to writer host
4750
conn.read_only = False
@@ -50,6 +53,9 @@
5053
conn.read_only = True
5154
with conn.cursor() as cursor_2:
5255
cursor_2.execute("SELECT * FROM bank_test")
56+
results = cursor_2.fetchall()
57+
for record in results:
58+
print(record)
5359

5460
# Tear down
5561
conn.read_only = False

docs/examples/PGFastestResponseStrategy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
conn.read_only = True
4343
with conn.cursor() as cursor_1:
4444
cursor_1.execute("SELECT * FROM bank_test")
45+
results = cursor_1.fetchall()
46+
for record in results:
47+
print(record)
4548

4649
# Switch to writer host
4750
conn.read_only = False

0 commit comments

Comments
 (0)