Skip to content

Commit

Permalink
Rename Process.connections() to Process.net_connections() (#2408)
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Apr 18, 2024
1 parent b6281c4 commit aefb59c
Show file tree
Hide file tree
Showing 28 changed files with 128 additions and 104 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
been reused. This makes `process_iter()`_ around 20x times faster.
- 2396_: a new ``psutil.process_iter.cache_clear()`` API can be used the clear
`process_iter()`_ internal cache.
- 2407_: `Process.connections()`_ was renamed to `Process.net_connections()`_.
The old name is still available, but it's deprecated (triggers a
``DeprecationWarning``) and will be removed in the future.

**Bug fixes**

Expand All @@ -37,6 +40,9 @@ Version 6.0.0 introduces some changes which affect backward compatibility:
been reused. If you want to check for PID reusage you are supposed to use
`Process.is_running()`_ against the yielded `Process`_ instances. That will
also automatically remove reused PIDs from `process_iter()`_ internal cache.
- 2407_: `Process.connections()`_ was renamed to `Process.net_connections()`_.
The old name is still available, but it's deprecated (triggers a
``DeprecationWarning``) and will be removed in the future.

5.9.8
=====
Expand Down Expand Up @@ -2644,6 +2650,7 @@ In most cases accessing the old names will work but it will cause a
.. _`Process.memory_maps()`: https://psutil.readthedocs.io/en/latest/#psutil.Process.memory_maps
.. _`Process.memory_percent()`: https://psutil.readthedocs.io/en/latest/#psutil.Process.memory_percent
.. _`Process.name()`: https://psutil.readthedocs.io/en/latest/#psutil.Process.name
.. _`Process.net_connections()`: https://psutil.readthedocs.io/en/latest/#psutil.Process.net_connections
.. _`Process.nice()`: https://psutil.readthedocs.io/en/latest/#psutil.Process.nice
.. _`Process.num_ctx_switches()`: https://psutil.readthedocs.io/en/latest/#psutil.Process.num_ctx_switches
.. _`Process.num_fds()`: https://psutil.readthedocs.io/en/latest/#psutil.Process.num_fds
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test-contracts: ## APIs sanity tests.
${MAKE} build
$(PYTHON_ENV_VARS) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_contracts.py

test-connections: ## Test net_connections() and Process.connections().
test-connections: ## Test psutil.net_connections() and Process.net_connections().
${MAKE} build
$(PYTHON_ENV_VARS) $(PYTHON) $(TSCRIPT) $(ARGS) psutil/tests/test_connections.py

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Process management
[popenfile(path='/home/giampaolo/monit.py', fd=3, position=0, mode='r', flags=32768),
popenfile(path='/var/log/monit.log', fd=4, position=235542, mode='a', flags=33793)]
>>>
>>> p.connections(kind='tcp')
>>> p.net_connections(kind='tcp')
[pconn(fd=115, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=48776), raddr=addr(ip='93.186.135.91', port=80), status='ESTABLISHED'),
pconn(fd=117, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=43761), raddr=addr(ip='72.14.234.100', port=80), status='CLOSING')]
>>>
Expand Down
4 changes: 1 addition & 3 deletions docs/DEVNOTES
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ FEATURES
Example:
```
df -a -> psutil.disk_partitions
lsof -> psutil.Process.open_files() and psutil.Process.open_connections()
lsof -> psutil.Process.open_files() and psutil.Process.net_connections()
killall-> (actual script)
tty -> psutil.Process.terminal()
who -> psutil.users()
Expand Down Expand Up @@ -113,8 +113,6 @@ REJECTED IDEAS
INCONSISTENCIES
===============

- `Process.connections()` should have been `Process.net_connections()` for
consistency with `psutil.net_connections()`.
- PROCFS_PATH should have been set_procfs_path().
- `virtual_memory()` should have been `memory_virtual()`.
- `swap_memory()` should have been `memory_swap()`.
Expand Down
31 changes: 21 additions & 10 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ Network
+----------------+-----------------------------------------------------+

On macOS and AIX this function requires root privileges.
To get per-process connections use :meth:`Process.connections`.
To get per-process connections use :meth:`Process.net_connections`.
Also, see `netstat.py`_ example script.
Example:

Expand Down Expand Up @@ -1221,7 +1221,7 @@ Process class

>>> import psutil
>>> psutil.Process().environ()
{'LC_NUMERIC': 'it_IT.UTF-8', 'QT_QPA_PLATFORMTHEME': 'appmenu-qt5', 'IM_CONFIG_PHASE': '1', 'XDG_GREETER_DATA_DIR': '/var/lib/lightdm-data/giampaolo', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'XDG_CURRENT_DESKTOP': 'Unity', 'UPSTART_EVENTS': 'started starting', 'GNOME_KEYRING_PID': '', 'XDG_VTNR': '7', 'QT_IM_MODULE': 'ibus', 'LOGNAME': 'giampaolo', 'USER': 'giampaolo', 'PATH': '/home/giampaolo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/giampaolo/svn/sysconf/bin', 'LC_PAPER': 'it_IT.UTF-8', 'GNOME_KEYRING_CONTROL': '', 'GTK_IM_MODULE': 'ibus', 'DISPLAY': ':0', 'LANG': 'en_US.UTF-8', 'LESS_TERMCAP_se': '\x1b[0m', 'TERM': 'xterm-256color', 'SHELL': '/bin/bash', 'XDG_SESSION_PATH': '/org/freedesktop/DisplayManager/Session0', 'XAUTHORITY': '/home/giampaolo/.Xauthority', 'LANGUAGE': 'en_US', 'COMPIZ_CONFIG_PROFILE': 'ubuntu', 'LC_MONETARY': 'it_IT.UTF-8', 'QT_LINUX_ACCESSIBILITY_ALWAYS_ON': '1', 'LESS_TERMCAP_me': '\x1b[0m', 'LESS_TERMCAP_md': '\x1b[01;38;5;74m', 'LESS_TERMCAP_mb': '\x1b[01;31m', 'HISTSIZE': '100000', 'UPSTART_INSTANCE': '', 'CLUTTER_IM_MODULE': 'xim', 'WINDOWID': '58786407', 'EDITOR': 'vim', 'SESSIONTYPE': 'gnome-session', 'XMODIFIERS': '@im=ibus', 'GPG_AGENT_INFO': '/home/giampaolo/.gnupg/S.gpg-agent:0:1', 'HOME': '/home/giampaolo', 'HISTFILESIZE': '100000', 'QT4_IM_MODULE': 'xim', 'GTK2_MODULES': 'overlay-scrollbar', 'XDG_SESSION_DESKTOP': 'ubuntu', 'SHLVL': '1', 'XDG_RUNTIME_DIR': '/run/user/1000', 'INSTANCE': 'Unity', 'LC_ADDRESS': 'it_IT.UTF-8', 'SSH_AUTH_SOCK': '/run/user/1000/keyring/ssh', 'VTE_VERSION': '4205', 'GDMSESSION': 'ubuntu', 'MANDATORY_PATH': '/usr/share/gconf/ubuntu.mandatory.path', 'VISUAL': 'vim', 'DESKTOP_SESSION': 'ubuntu', 'QT_ACCESSIBILITY': '1', 'XDG_SEAT_PATH': '/org/freedesktop/DisplayManager/Seat0', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'XDG_SESSION_ID': 'c2', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-9GAJpvnt8r', '_': '/usr/bin/python', 'DEFAULTS_PATH': '/usr/share/gconf/ubuntu.default.path', 'LC_IDENTIFICATION': 'it_IT.UTF-8', 'LESS_TERMCAP_ue': '\x1b[0m', 'UPSTART_SESSION': 'unix:abstract=/com/ubuntu/upstart-session/1000/1294', 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg', 'GTK_MODULES': 'gail:atk-bridge:unity-gtk-module', 'XDG_SESSION_TYPE': 'x11', 'PYTHONSTARTUP': '/home/giampaolo/.pythonstart', 'LC_NAME': 'it_IT.UTF-8', 'OLDPWD': '/home/giampaolo/svn/curio_giampaolo/tests', 'GDM_LANG': 'en_US', 'LC_TELEPHONE': 'it_IT.UTF-8', 'HISTCONTROL': 'ignoredups:erasedups', 'LC_MEASUREMENT': 'it_IT.UTF-8', 'PWD': '/home/giampaolo/svn/curio_giampaolo', 'JOB': 'gnome-session', 'LESS_TERMCAP_us': '\x1b[04;38;5;146m', 'UPSTART_JOB': 'unity-settings-daemon', 'LC_TIME': 'it_IT.UTF-8', 'LESS_TERMCAP_so': '\x1b[38;5;246m', 'PAGER': 'less', 'XDG_DATA_DIRS': '/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop', 'XDG_SEAT': 'seat0'}
{'LC_NUMERIC': 'it_IT.UTF-8', 'QT_QPA_PLATFORMTHEME': 'appmenu-qt5', 'IM_CONFIG_PHASE': '1', 'XDG_GREETER_DATA_DIR': '/var/lib/lightdm-data/giampaolo', 'XDG_CURRENT_DESKTOP': 'Unity', 'UPSTART_EVENTS': 'started starting', 'GNOME_KEYRING_PID': '', 'XDG_VTNR': '7', 'QT_IM_MODULE': 'ibus', 'LOGNAME': 'giampaolo', 'USER': 'giampaolo', 'PATH': '/home/giampaolo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/giampaolo/svn/sysconf/bin', 'LC_PAPER': 'it_IT.UTF-8', 'GNOME_KEYRING_CONTROL': '', 'GTK_IM_MODULE': 'ibus', 'DISPLAY': ':0', 'LANG': 'en_US.UTF-8', 'LESS_TERMCAP_se': '\x1b[0m', 'TERM': 'xterm-256color', 'SHELL': '/bin/bash', 'XDG_SESSION_PATH': '/org/freedesktop/DisplayManager/Session0', 'XAUTHORITY': '/home/giampaolo/.Xauthority', 'LANGUAGE': 'en_US', 'COMPIZ_CONFIG_PROFILE': 'ubuntu', 'LC_MONETARY': 'it_IT.UTF-8', 'QT_LINUX_ACCESSIBILITY_ALWAYS_ON': '1', 'LESS_TERMCAP_me': '\x1b[0m', 'LESS_TERMCAP_md': '\x1b[01;38;5;74m', 'LESS_TERMCAP_mb': '\x1b[01;31m', 'HISTSIZE': '100000', 'UPSTART_INSTANCE': '', 'CLUTTER_IM_MODULE': 'xim', 'WINDOWID': '58786407', 'EDITOR': 'vim', 'SESSIONTYPE': 'gnome-session', 'XMODIFIERS': '@im=ibus', 'GPG_AGENT_INFO': '/home/giampaolo/.gnupg/S.gpg-agent:0:1', 'HOME': '/home/giampaolo', 'HISTFILESIZE': '100000', 'QT4_IM_MODULE': 'xim', 'GTK2_MODULES': 'overlay-scrollbar', 'XDG_SESSION_DESKTOP': 'ubuntu', 'SHLVL': '1', 'XDG_RUNTIME_DIR': '/run/user/1000', 'INSTANCE': 'Unity', 'LC_ADDRESS': 'it_IT.UTF-8', 'SSH_AUTH_SOCK': '/run/user/1000/keyring/ssh', 'VTE_VERSION': '4205', 'GDMSESSION': 'ubuntu', 'MANDATORY_PATH': '/usr/share/gconf/ubuntu.mandatory.path', 'VISUAL': 'vim', 'DESKTOP_SESSION': 'ubuntu', 'QT_ACCESSIBILITY': '1', 'XDG_SEAT_PATH': '/org/freedesktop/DisplayManager/Seat0', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'XDG_SESSION_ID': 'c2', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-9GAJpvnt8r', '_': '/usr/bin/python', 'DEFAULTS_PATH': '/usr/share/gconf/ubuntu.default.path', 'LC_IDENTIFICATION': 'it_IT.UTF-8', 'LESS_TERMCAP_ue': '\x1b[0m', 'UPSTART_SESSION': 'unix:abstract=/com/ubuntu/upstart-session/1000/1294', 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg', 'GTK_MODULES': 'gail:atk-bridge:unity-gtk-module', 'XDG_SESSION_TYPE': 'x11', 'PYTHONSTARTUP': '/home/giampaolo/.pythonstart', 'LC_NAME': 'it_IT.UTF-8', 'OLDPWD': '/home/giampaolo/svn/curio_giampaolo/tests', 'GDM_LANG': 'en_US', 'LC_TELEPHONE': 'it_IT.UTF-8', 'HISTCONTROL': 'ignoredups:erasedups', 'LC_MEASUREMENT': 'it_IT.UTF-8', 'PWD': '/home/giampaolo/svn/curio_giampaolo', 'JOB': 'gnome-session', 'LESS_TERMCAP_us': '\x1b[04;38;5;146m', 'UPSTART_JOB': 'unity-settings-daemon', 'LC_TIME': 'it_IT.UTF-8', 'LESS_TERMCAP_so': '\x1b[38;5;246m', 'PAGER': 'less', 'XDG_DATA_DIRS': '/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop', 'XDG_SEAT': 'seat0'}

.. note::
on macOS Big Sur this function returns something meaningful only for the
Expand Down Expand Up @@ -1251,7 +1251,7 @@ Process class
If *attrs* is specified it must be a list of strings reflecting available
:class:`Process` class's attribute names. Here's a list of possible string
values:
``'cmdline'``, ``'connections'``, ``'cpu_affinity'``, ``'cpu_num'``, ``'cpu_percent'``, ``'cpu_times'``, ``'create_time'``, ``'cwd'``, ``'environ'``, ``'exe'``, ``'gids'``, ``'io_counters'``, ``'ionice'``, ``'memory_full_info'``, ``'memory_info'``, ``'memory_maps'``, ``'memory_percent'``, ``'name'``, ``'nice'``, ``'num_ctx_switches'``, ``'num_fds'``, ``'num_handles'``, ``'num_threads'``, ``'open_files'``, ``'pid'``, ``'ppid'``, ``'status'``, ``'terminal'``, ``'threads'``, ``'uids'``, ``'username'```.
``'cmdline'``, ``'net_connections'``, ``'cpu_affinity'``, ``'cpu_num'``, ``'cpu_percent'``, ``'cpu_times'``, ``'create_time'``, ``'cwd'``, ``'environ'``, ``'exe'``, ``'gids'``, ``'io_counters'``, ``'ionice'``, ``'memory_full_info'``, ``'memory_info'``, ``'memory_maps'``, ``'memory_percent'``, ``'name'``, ``'nice'``, ``'num_ctx_switches'``, ``'num_fds'``, ``'num_handles'``, ``'num_threads'``, ``'open_files'``, ``'pid'``, ``'ppid'``, ``'status'``, ``'terminal'``, ``'threads'``, ``'uids'``, ``'username'```.
If *attrs* argument is not passed all public read only attributes are
assumed.
*ad_value* is the value which gets assigned to a dict key in case
Expand All @@ -1267,7 +1267,7 @@ Process class
>>>
>>> # get a list of valid attrs names
>>> list(psutil.Process().as_dict().keys())
['status', 'cpu_num', 'num_ctx_switches', 'pid', 'memory_full_info', 'connections', 'cmdline', 'create_time', 'ionice', 'num_fds', 'memory_maps', 'cpu_percent', 'terminal', 'ppid', 'cwd', 'nice', 'username', 'cpu_times', 'io_counters', 'memory_info', 'threads', 'open_files', 'name', 'num_threads', 'exe', 'uids', 'gids', 'cpu_affinity', 'memory_percent', 'environ']
['cmdline', 'connections', 'cpu_affinity', 'cpu_num', 'cpu_percent', 'cpu_times', 'create_time', 'cwd', 'environ', 'exe', 'gids', 'io_counters', 'ionice', 'memory_full_info', 'memory_info', 'memory_maps', 'memory_percent', 'name', 'net_connections', 'nice', 'num_ctx_switches', 'num_fds', 'num_threads', 'open_files', 'pid', 'ppid', 'status', 'terminal', 'threads', 'uids', 'username']

.. versionchanged::
3.0.0 *ad_value* is used also when incurring into
Expand Down Expand Up @@ -1896,15 +1896,16 @@ Process class
.. versionchanged::
4.1.0 new *position*, *mode* and *flags* fields on Linux.

.. method:: connections(kind="inet")
.. method:: net_connections(kind="inet")

Return socket connections opened by process as a list of named tuples.
To get system-wide connections use :func:`psutil.net_connections()`.
Every named tuple provides 6 attributes:

- **fd**: the socket file descriptor. This can be passed to `socket.fromfd`_
to obtain a usable socket object. On Windows, FreeBSD and SunOS this is
always set to ``-1``.
- **fd**: the socket file descriptor. If the connection refers to the
current process this may be passed to `socket.fromfd`_ to obtain a usable
socket object.
On Windows, FreeBSD and SunOS this is always set to ``-1``.
- **family**: the address family, either `AF_INET`_, `AF_INET6`_ or
`AF_UNIX`_.
- **type**: the address type, either `SOCK_STREAM`_, `SOCK_DGRAM`_ or
Expand Down Expand Up @@ -1955,7 +1956,7 @@ Process class
>>> p = psutil.Process(1694)
>>> p.name()
'firefox'
>>> p.connections()
>>> p.net_connections()
[pconn(fd=115, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=48776), raddr=addr(ip='93.186.135.91', port=80), status='ESTABLISHED'),
pconn(fd=117, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=43761), raddr=addr(ip='72.14.234.100', port=80), status='CLOSING'),
pconn(fd=119, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=60759), raddr=addr(ip='72.14.234.104', port=80), status='ESTABLISHED'),
Expand All @@ -1978,6 +1979,16 @@ Process class

.. versionchanged:: 5.3.0 : *laddr* and *raddr* are named tuples.

.. versionchanged:: 6.0.0 : method renamed from `connections` to
`net_connections`.

.. method:: connections()

Same as :meth:`net_connections` (deprecated).

.. warning::
deprecated in version 6.0.0; use :meth:`net_connections` instead.

.. method:: is_running()

Return whether the current process is running in the current process list.
Expand Down Expand Up @@ -2386,7 +2397,7 @@ Connections constants
.. data:: CONN_BOUND (Solaris)

A set of strings representing the status of a TCP connection.
Returned by :meth:`psutil.Process.connections()` and
Returned by :meth:`psutil.Process.net_connections()` and
:func:`psutil.net_connections` (`status` field).

Hardware constants
Expand Down
8 changes: 6 additions & 2 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ def open_files(self):
"""
return self._proc.open_files()

def connections(self, kind='inet'):
def net_connections(self, kind='inet'):
"""Return socket connections opened by process as a list of
(fd, family, type, laddr, raddr, status) namedtuples.
The *kind* parameter filters for connections that match the
Expand All @@ -1220,7 +1220,11 @@ def connections(self, kind='inet'):
| all | the sum of all the possible families and protocols |
+------------+----------------------------------------------------+
"""
return self._proc.connections(kind)
return self._proc.net_connections(kind)

@_common.deprecated_method(replacement="net_connections")
def connections(self, kind="inet"):
return self.net_connections(kind=kind)

# --- signals

Expand Down
8 changes: 4 additions & 4 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
STATUS_SUSPENDED = "suspended" # NetBSD
STATUS_PARKED = "parked" # Linux

# Process.connections() and psutil.net_connections()
# Process.net_connections() and psutil.net_connections()
CONN_ESTABLISHED = "ESTABLISHED"
CONN_SYN_SENT = "SYN_SENT"
CONN_SYN_RECV = "SYN_RECV"
Expand Down Expand Up @@ -242,17 +242,17 @@ class BatteryTime(enum.IntEnum):
pionice = namedtuple('pionice', ['ioclass', 'value'])
# psutil.Process.ctx_switches()
pctxsw = namedtuple('pctxsw', ['voluntary', 'involuntary'])
# psutil.Process.connections()
# psutil.Process.net_connections()
pconn = namedtuple(
'pconn', ['fd', 'family', 'type', 'laddr', 'raddr', 'status']
)

# psutil.connections() and psutil.Process.connections()
# psutil.net_connections() and psutil.Process.net_connections()
addr = namedtuple('addr', ['ip', 'port'])


# ===================================================================
# --- Process.connections() 'kind' parameter mapping
# --- Process.net_connections() 'kind' parameter mapping
# ===================================================================


Expand Down
2 changes: 1 addition & 1 deletion psutil/_psaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def threads(self):
return retlist

@wrap_exceptions
def connections(self, kind='inet'):
def net_connections(self, kind='inet'):
ret = net_connections(kind, _pid=self.pid)
# The underlying C implementation retrieves all OS connections
# and filters them by PID. At this point we can't tell whether
Expand Down
4 changes: 2 additions & 2 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def threads(self):
return retlist

@wrap_exceptions
def connections(self, kind='inet'):
def net_connections(self, kind='inet'):
if kind not in conn_tmap:
raise ValueError(
"invalid %r kind argument; choose between %s"
Expand All @@ -835,7 +835,7 @@ def connections(self, kind='inet'):
elif OPENBSD:
rawlist = cext.net_connections(self.pid, families, types)
else:
rawlist = cext.proc_connections(self.pid, families, types)
rawlist = cext.proc_net_connections(self.pid, families, types)

for item in rawlist:
fd, fam, type, laddr, raddr, status = item[:6]
Expand Down
14 changes: 7 additions & 7 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ class _Ipv6UnsupportedError(Exception):
pass


class Connections:
class NetConnections:
"""A wrapper on top of /proc/net/* files, retrieving per-process
and system-wide open connections (TCP, UDP, UNIX) similarly to
"netstat -an".
Expand Down Expand Up @@ -981,8 +981,8 @@ def process_inet(file, family, type_, inodes, filter_pid=None):
else:
status = _common.CONN_NONE
try:
laddr = Connections.decode_address(laddr, family)
raddr = Connections.decode_address(raddr, family)
laddr = NetConnections.decode_address(laddr, family)
raddr = NetConnections.decode_address(raddr, family)
except _Ipv6UnsupportedError:
continue
yield (fd, family, type_, laddr, raddr, status, pid)
Expand Down Expand Up @@ -1059,12 +1059,12 @@ def retrieve(self, kind, pid=None):
return list(ret)


_connections = Connections()
_net_connections = NetConnections()


def net_connections(kind='inet'):
"""Return system-wide open connections."""
return _connections.retrieve(kind)
return _net_connections.retrieve(kind)


def net_io_counters():
Expand Down Expand Up @@ -2344,8 +2344,8 @@ def open_files(self):
return retlist

@wrap_exceptions
def connections(self, kind='inet'):
ret = _connections.retrieve(kind, self.pid)
def net_connections(self, kind='inet'):
ret = _net_connections.retrieve(kind, self.pid)
self._raise_if_not_alive()
return ret

Expand Down

0 comments on commit aefb59c

Please sign in to comment.