From 20ed8f9b3d53847408e08442857704590d4f8b4c Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 18 Apr 2024 11:23:09 +0200 Subject: [PATCH 1/2] #2408: ignore old "connections" name into as_dict() --- psutil/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psutil/__init__.py b/psutil/__init__.py index ba90d097a..e1e2b7d5d 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -1341,7 +1341,7 @@ def wait(self, timeout=None): [x for x in dir(Process) if not x.startswith('_') and x not in {'send_signal', 'suspend', 'resume', 'terminate', 'kill', 'wait', 'is_running', 'as_dict', 'parent', 'parents', 'children', 'rlimit', - 'memory_info_ex', 'oneshot'}]) + 'memory_info_ex', 'connections', 'oneshot'}]) # fmt: on From 8bfecf0459216f67b1ec089ced03dd162fca75de Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 18 Apr 2024 14:00:29 +0200 Subject: [PATCH 2/2] #2408: fix some tests which were still failing due to the old name Signed-off-by: Giampaolo Rodola --- psutil/tests/test_process.py | 6 +++--- scripts/procinfo.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 9613eac18..44a5e8901 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -1207,9 +1207,9 @@ def test_as_dict(self): self.assertEqual(sorted(d.keys()), ['exe', 'name']) p = psutil.Process(min(psutil.pids())) - d = p.as_dict(attrs=['connections'], ad_value='foo') - if not isinstance(d['connections'], list): - self.assertEqual(d['connections'], 'foo') + d = p.as_dict(attrs=['net_connections'], ad_value='foo') + if not isinstance(d['net_connections'], list): + self.assertEqual(d['net_connections'], 'foo') # Test ad_value is set on AccessDenied. with mock.patch( diff --git a/scripts/procinfo.py b/scripts/procinfo.py index 95c99d442..24004a960 100755 --- a/scripts/procinfo.py +++ b/scripts/procinfo.py @@ -241,13 +241,13 @@ def run(pid, verbose=False): else: print_('open-files', '') - if pinfo['connections']: + if pinfo['net_connections']: template = '%-5s %-25s %-25s %s' print_( 'connections', template % ('PROTO', 'LOCAL ADDR', 'REMOTE ADDR', 'STATUS'), ) - for conn in pinfo['connections']: + for conn in pinfo['net_connections']: if conn.type == socket.SOCK_STREAM: type = 'TCP' elif conn.type == socket.SOCK_DGRAM: