Skip to content

Commit 34265fb

Browse files
authored
infra: cleanup filterwarnings (#2569)
<!-- Thanks for opening a pull request! --> <!-- In the case this PR will resolve an issue, please replace ${GITHUB_ISSUE_ID} below with the actual Github issue id. --> <!-- Closes #${GITHUB_ISSUE_ID} --> # Rationale for this change cleanup! ## Are these changes tested? ## Are there any user-facing changes? <!-- In the case of user-facing changes, please add the changelog label. -->
1 parent 3e46596 commit 34265fb

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

pyiceberg/catalog/hive.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ def __enter__(self) -> Client:
185185
try:
186186
self._transport.open()
187187
except (TypeError, TTransport.TTransportException):
188+
# Close the old transport before reinitializing to prevent resource leaks
189+
try:
190+
self._transport.close()
191+
except Exception:
192+
pass
188193
# reinitialize _transport
189194
self._transport = self._init_thrift_transport()
190195
self._transport.open()

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,6 @@ markers = [
346346
# Turns a warning into an error
347347
filterwarnings = [
348348
"error",
349-
"ignore:A plugin raised an exception during an old-style hookwrapper teardown.",
350-
"ignore:unclosed <socket.socket",
351349
# Remove this in a future release of PySpark.
352350
"ignore:distutils Version classes are deprecated. Use packaging.version instead.",
353351
# Remove this in a future release of PySpark. https://github.com/apache/iceberg-python/issues/1349

tests/catalog/test_hive.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def __init__(self, socket: thrift.transport.TSocket.TServerSocket, response: byt
204204
self._response = response
205205
self._port = None
206206
self._port_bound = threading.Event()
207+
self._clients: list[thrift.transport.TSocket.TSocket] = [] # Track accepted client connections
207208

208209
def run(self) -> None:
209210
self._socket.listen()
@@ -222,6 +223,7 @@ def run(self) -> None:
222223
try:
223224
client = self._socket.accept()
224225
if client:
226+
self._clients.append(client) # Track the client
225227
client.write(self._response)
226228
client.flush()
227229
except Exception:
@@ -233,6 +235,12 @@ def port(self) -> Optional[int]:
233235
return self._port
234236

235237
def close(self) -> None:
238+
# Close all client connections first
239+
for client in self._clients:
240+
try:
241+
client.close()
242+
except Exception:
243+
pass
236244
self._socket.close()
237245

238246

@@ -1392,6 +1400,7 @@ def test_create_hive_client_with_kerberos_using_context_manager(
13921400
with client as open_client:
13931401
assert open_client._iprot.trans.isOpen()
13941402

1403+
assert not open_client._iprot.trans.isOpen()
13951404
# Use the context manager a second time to see if
13961405
# closing and re-opening work as expected.
13971406
with client as open_client:

0 commit comments

Comments
 (0)