cmcfarlen commented on code in PR #10103:
URL: https://github.com/apache/trafficserver/pull/10103#discussion_r1276561882
##########
tests/gold_tests/autest-site/ports.py:
##########
@@ -115,6 +127,30 @@ def _get_available_port(queue):
return port
+def _get_listening_ports() -> set[int]:
+ """Use psutil to get the set of ports that are currently listening.
+
+ :return: The set of ports that are currently listening.
+ """
+ ports: set[int] = set()
+ try:
+ connections = psutil.net_connections(kind='all')
+ for conn in connections:
+ if conn.status == psutil.CONN_LISTEN:
+ ports.add(conn.laddr.port)
+ except psutil.AccessDenied:
+ # Mac OS X doesn't allow net_connections() to be called without root.
+ for proc in psutil.process_iter(['pid', 'name']):
+ try:
+ connections = proc.connections(kind='all')
+ except (psutil.AccessDenied, psutil.NoSuchProcess):
+ continue
+ for conn in connections:
+ if conn.status == psutil.CONN_LISTEN:
+ ports.add(conn.laddr.port)
Review Comment:
not familiar with python and scoping, but to me this for loop looks odd
outside the try that assigns to connections
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]