Skip to content

Commit 05a6245

Browse files
committed
BUG: Fix missing "server_close" method on SAMPHubProxy
It's possible this bug has existed for a long time and was just hidden. Another possibility is it appeared at some point during refactoring, but as far as I can tell it's been around a long time. The `SAMPWebClient.hub` attribute is still just a `SAMPHubProxy`; it does not make sense for it to have a `server_close` method because it does not itself run or wrap a server. It does however manage a pool of XML-RPC client connections which is deleted when calling `SAMPHubProxy.disconnect()`. To be on the safe side I added a `ServerProxyPool.shutdown()` method to the proxy pool class which closes the client connections. This is called when shutting down the `SAMPWebClient` server loop. Unlike the normal `SAMPClient` class, the `SAMPWebClient` used only in tests never runs a TCP server of its own, so calling `server_close` anywhere in here does not make sense.
1 parent d971b1c commit 05a6245

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎astropy/samp/hub_proxy.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,12 @@ def disconnect(self):
8888
"""
8989
Disconnect from the current SAMP Hub.
9090
"""
91-
self.proxy = None
91+
if self.proxy is not None:
92+
self.proxy.shutdown()
93+
self.proxy = None
9294
self._connected = False
9395
self.lockfile = {}
9496

95-
def server_close(self):
96-
self.proxy.server_close()
97-
9897
@property
9998
def _samp_hub(self):
10099
"""

‎astropy/samp/tests/web_profile_test_helpers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def _serve_forever(self):
172172
self.receive_response(self._private_key,
173173
*result['samp.params'])
174174

175-
self.hub.server_close()
175+
self.hub.disconnect()
176176

177177
def register(self):
178178
"""

‎astropy/samp/utils.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ def __getattr__(self, name):
8282
# magic method dispatcher
8383
return _ServerProxyPoolMethod(self._proxies, name)
8484

85+
def shutdown(self):
86+
"""Shut down the proxy pool but closing all active conections."""
87+
88+
while True:
89+
try:
90+
proxy = self._proxies.get_nowait()
91+
except queue.Empty:
92+
break
93+
# An undocumented but apparently supported way to call methods on
94+
# an ServerProxy that are not dispatched to the remote server
95+
proxy('close')
96+
8597

8698
class SAMPMsgReplierWrapper:
8799
"""

‎setup.cfg‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ filterwarnings =
138138
# Ignore a warning we emit about not supporting the parallel
139139
# reading option for now, can be removed once the issue is fixed
140140
ignore:parallel reading does not currently work, so falling back to serial
141-
# Ignore pytest.PytestUnhandledThreadExceptionWarning from SAMP, pytest>=6.2
142-
ignore:Exception in thread
143141
ignore:'datfix' made the change:astropy.wcs.wcs.FITSFixedWarning
144142
doctest_norecursedirs =
145143
*/setup_package.py

0 commit comments

Comments
 (0)