diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-07-04 14:19:52 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-07-04 14:32:26 +0300 |
commit | 96a956ca6ae158f077e047ad771b422d0a64205c (patch) | |
tree | 04d91a428b8821e0d0fb98a6f6f57105ae865c6a /contrib | |
parent | ce6a61d6d5fdd61a81500a2d4fea9a4d25d4433c (diff) | |
download | ydb-96a956ca6ae158f077e047ad771b422d0a64205c.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib')
20 files changed, 197 insertions, 212 deletions
diff --git a/contrib/python/psutil/py3/.dist-info/METADATA b/contrib/python/psutil/py3/.dist-info/METADATA index 1815b243bc..193553c957 100644 --- a/contrib/python/psutil/py3/.dist-info/METADATA +++ b/contrib/python/psutil/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: psutil -Version: 5.9.8 +Version: 6.0.0 Summary: Cross-platform lib for process and system monitoring in Python. Home-page: https://github.com/giampaolo/psutil Author: Giampaolo Rodola @@ -82,11 +82,11 @@ Requires-Dist: wmi ; (sys_platform == "win32") and extra == 'test' :target: https://github.com/giampaolo/psutil/graphs/contributors :alt: Contributors -.. |github-actions-wheels| image:: https://img.shields.io/github/actions/workflow/status/giampaolo/psutil/.github/workflows/build.yml?label=Linux%2C%20macOS%2C%20Windows +.. |github-actions-wheels| image:: https://img.shields.io/github/actions/workflow/status/giampaolo/psutil/.github/workflows/build.yml.svg?label=Linux%2C%20macOS%2C%20Windows :target: https://github.com/giampaolo/psutil/actions?query=workflow%3Abuild :alt: Linux, macOS, Windows -.. |github-actions-bsd| image:: https://img.shields.io/github/actions/workflow/status/giampaolo/psutil/.github/workflows/bsd.yml?label=FreeBSD,%20NetBSD,%20OpenBSD +.. |github-actions-bsd| image:: https://img.shields.io/github/actions/workflow/status/giampaolo/psutil/.github/workflows/bsd.yml.svg?label=FreeBSD,%20NetBSD,%20OpenBSD :target: https://github.com/giampaolo/psutil/actions?query=workflow%3Absd-tests :alt: FreeBSD, NetBSD, OpenBSD @@ -251,8 +251,8 @@ Disks .. code-block:: python >>> psutil.disk_partitions() - [sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid', maxfile=255, maxpath=4096), - sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext', opts='rw', maxfile=255, maxpath=4096)] + [sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'), + sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext', opts='rw')] >>> >>> psutil.disk_usage('/') sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5) @@ -405,7 +405,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')] >>> diff --git a/contrib/python/psutil/py3/README.rst b/contrib/python/psutil/py3/README.rst index 12bf64254e..3fc6e601b1 100644 --- a/contrib/python/psutil/py3/README.rst +++ b/contrib/python/psutil/py3/README.rst @@ -18,11 +18,11 @@ :target: https://github.com/giampaolo/psutil/graphs/contributors :alt: Contributors -.. |github-actions-wheels| image:: https://img.shields.io/github/actions/workflow/status/giampaolo/psutil/.github/workflows/build.yml?label=Linux%2C%20macOS%2C%20Windows +.. |github-actions-wheels| image:: https://img.shields.io/github/actions/workflow/status/giampaolo/psutil/.github/workflows/build.yml.svg?label=Linux%2C%20macOS%2C%20Windows :target: https://github.com/giampaolo/psutil/actions?query=workflow%3Abuild :alt: Linux, macOS, Windows -.. |github-actions-bsd| image:: https://img.shields.io/github/actions/workflow/status/giampaolo/psutil/.github/workflows/bsd.yml?label=FreeBSD,%20NetBSD,%20OpenBSD +.. |github-actions-bsd| image:: https://img.shields.io/github/actions/workflow/status/giampaolo/psutil/.github/workflows/bsd.yml.svg?label=FreeBSD,%20NetBSD,%20OpenBSD :target: https://github.com/giampaolo/psutil/actions?query=workflow%3Absd-tests :alt: FreeBSD, NetBSD, OpenBSD @@ -150,6 +150,7 @@ Supporters <a href="https://github.com/robusta-dev"><img height="40" width="40" title="Robusta" src="https://avatars.githubusercontent.com/u/82757710?s=200&v=4" /></a> <a href="https://github.com/JeremyGrosser"><img height="40" width="40" title="JeremyGrosser" src="https://avatars.githubusercontent.com/u/2151?v=4" /></a> <a href="https://github.com/getsentry"><img height="40" width="40" title="getsentry" src="https://avatars.githubusercontent.com/u/1396951?s=200&v=4" /></a> + <a href="https://github.com/c0m4r"><img height="40" width="40" title="c0m4r" src="https://avatars.githubusercontent.com/u/6292788?v=4" /></a> </div> <sup><a href="https://github.com/sponsors/giampaolo">add your avatar</a></sup> @@ -227,8 +228,8 @@ Disks .. code-block:: python >>> psutil.disk_partitions() - [sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid', maxfile=255, maxpath=4096), - sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext', opts='rw', maxfile=255, maxpath=4096)] + [sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'), + sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext', opts='rw')] >>> >>> psutil.disk_usage('/') sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5) @@ -381,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')] >>> diff --git a/contrib/python/psutil/py3/psutil/__init__.py b/contrib/python/psutil/py3/psutil/__init__.py index 8138db41e1..3a503503cc 100644 --- a/contrib/python/psutil/py3/psutil/__init__.py +++ b/contrib/python/psutil/py3/psutil/__init__.py @@ -85,6 +85,7 @@ from ._common import Error from ._common import NoSuchProcess from ._common import TimeoutExpired from ._common import ZombieProcess +from ._common import debug from ._common import memoize_when_activated from ._common import wrap_numbers as _wrap_numbers from ._compat import PY3 as _PY3 @@ -213,7 +214,7 @@ if hasattr(_psplatform.Process, "rlimit"): AF_LINK = _psplatform.AF_LINK __author__ = "Giampaolo Rodola'" -__version__ = "5.9.8" +__version__ = "6.0.0" version_info = tuple([int(num) for num in __version__.split('.')]) _timer = getattr(time, 'monotonic', time.time) @@ -291,11 +292,9 @@ class Process(object): # noqa: UP004 If PID is omitted current process PID (os.getpid()) is used. Raise NoSuchProcess if PID does not exist. - Note that most of the methods of this class do not make sure - the PID of the process being queried has been reused over time. - That means you might end up retrieving an information referring - to another process in case the original one this instance - refers to is gone in the meantime. + Note that most of the methods of this class do not make sure that + the PID of the process being queried has been reused. That means + that you may end up retrieving information for another process. The only exceptions for which process identity is pre-emptively checked and guaranteed are: @@ -312,11 +311,8 @@ class Process(object): # noqa: UP004 - terminate() - kill() - To prevent this problem for all other methods you can: - - use is_running() before querying the process - - if you're continuously iterating over a set of Process - instances use process_iter() which pre-emptively checks - process identity for every yielded instance + To prevent this problem for all other methods you can use + is_running() before querying the process. """ def __init__(self, pid=None): @@ -384,19 +380,24 @@ class Process(object): # noqa: UP004 if self._name: info['name'] = self._name with self.oneshot(): - try: - info["name"] = self.name() - info["status"] = self.status() - except ZombieProcess: - info["status"] = "zombie" - except NoSuchProcess: - info["status"] = "terminated" - except AccessDenied: - pass + if self._pid_reused: + info["status"] = "terminated + PID reused" + else: + try: + info["name"] = self.name() + info["status"] = self.status() + except ZombieProcess: + info["status"] = "zombie" + except NoSuchProcess: + info["status"] = "terminated" + except AccessDenied: + pass + if self._exitcode not in (_SENTINEL, None): info["exitcode"] = self._exitcode if self._create_time is not None: info['started'] = _pprint_secs(self._create_time) + return "%s.%s(%s)" % ( self.__class__.__module__, self.__class__.__name__, @@ -436,7 +437,7 @@ class Process(object): # noqa: UP004 def _raise_if_pid_reused(self): """Raises NoSuchProcess in case process PID has been reused.""" - if not self.is_running() and self._pid_reused: + if self._pid_reused or (not self.is_running() and self._pid_reused): # We may directly raise NSP in here already if PID is just # not running, but I prefer NSP to be raised naturally by # the actual Process API call. This way unit tests will tell @@ -599,19 +600,23 @@ class Process(object): # noqa: UP004 def is_running(self): """Return whether this process is running. - It also checks if PID has been reused by another process in - which case return False. + + It also checks if PID has been reused by another process, in + which case it will remove the process from `process_iter()` + internal cache and return False. """ if self._gone or self._pid_reused: return False try: # Checking if PID is alive is not enough as the PID might - # have been reused by another process: we also want to - # verify process identity. - # Process identity / uniqueness over time is guaranteed by - # (PID + creation time) and that is verified in __eq__. + # have been reused by another process. Process identity / + # uniqueness over time is guaranteed by (PID + creation + # time) and that is verified in __eq__. self._pid_reused = self != Process(self.pid) - return not self._pid_reused + if self._pid_reused: + _pids_reused.add(self.pid) + raise NoSuchProcess(self.pid) + return True except ZombieProcess: # We should never get here as it's already handled in # Process.__init__; here just for extra safety. @@ -1193,7 +1198,7 @@ class Process(object): # noqa: UP004 """ 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 @@ -1215,7 +1220,11 @@ class Process(object): # noqa: UP004 | 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 @@ -1332,7 +1341,7 @@ _as_dict_attrnames = set( [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 @@ -1455,6 +1464,7 @@ def pid_exists(pid): _pmap = {} +_pids_reused = set() def process_iter(attrs=None, ad_value=None): @@ -1463,10 +1473,7 @@ def process_iter(attrs=None, ad_value=None): Every new Process instance is only created once and then cached into an internal table which is updated every time this is used. - - Cached Process instances are checked for identity so that you're - safe in case a PID has been reused by another process, in which - case the cached instance is updated. + Cache can optionally be cleared via `process_iter.clear_cache()`. The sorting order in which processes are yielded is based on their PIDs. @@ -1482,8 +1489,6 @@ def process_iter(attrs=None, ad_value=None): def add(pid): proc = Process(pid) - if attrs is not None: - proc.info = proc.as_dict(attrs=attrs, ad_value=ad_value) pmap[proc.pid] = proc return proc @@ -1497,43 +1502,29 @@ def process_iter(attrs=None, ad_value=None): gone_pids = b - a for pid in gone_pids: remove(pid) + while _pids_reused: + pid = _pids_reused.pop() + debug("refreshing Process instance for reused PID %s" % pid) + remove(pid) try: ls = sorted(list(pmap.items()) + list(dict.fromkeys(new_pids).items())) for pid, proc in ls: try: if proc is None: # new process - yield add(pid) - else: - # use is_running() to check whether PID has been - # reused by another process in which case yield a - # new Process instance - if proc.is_running(): - if attrs is not None: - proc.info = proc.as_dict( - attrs=attrs, ad_value=ad_value - ) - yield proc - else: - yield add(pid) + proc = add(pid) + if attrs is not None: + proc.info = proc.as_dict(attrs=attrs, ad_value=ad_value) + yield proc except NoSuchProcess: remove(pid) - except AccessDenied: - # Process creation time can't be determined hence there's - # no way to tell whether the pid of the cached process - # has been reused. Just return the cached version. - if proc is None and pid in pmap: - try: - yield pmap[pid] - except KeyError: - # If we get here it is likely that 2 threads were - # using process_iter(). - pass - else: - raise finally: _pmap = pmap +process_iter.cache_clear = lambda: _pmap.clear() # noqa +process_iter.cache_clear.__doc__ = "Clear process_iter() internal cache." + + def wait_procs(procs, timeout=None, callback=None): """Convenience function which waits for a list of processes to terminate. @@ -1615,14 +1606,14 @@ def wait_procs(procs, timeout=None, callback=None): check_gone(proc, timeout) else: check_gone(proc, max_timeout) - alive = alive - gone + alive = alive - gone # noqa PLR6104 if alive: # Last attempt over processes survived so far. # timeout == 0 won't make this function wait any further. for proc in alive: check_gone(proc, 0) - alive = alive - gone + alive = alive - gone # noqa: PLR6104 return (list(gone), list(alive)) @@ -2037,7 +2028,7 @@ def swap_memory(): # ===================================================================== -# --- disks/paritions related functions +# --- disks/partitions related functions # ===================================================================== @@ -2058,25 +2049,7 @@ def disk_partitions(all=False): If *all* parameter is False return physical devices only and ignore all others. """ - - def pathconf(path, name): - try: - return os.pathconf(path, name) - except (OSError, AttributeError): - pass - - ret = _psplatform.disk_partitions(all) - if POSIX: - new = [] - for item in ret: - nt = item._replace( - maxfile=pathconf(item.mountpoint, 'PC_NAME_MAX'), - maxpath=pathconf(item.mountpoint, 'PC_PATH_MAX'), - ) - new.append(nt) - return new - else: - return ret + return _psplatform.disk_partitions(all) def disk_io_counters(perdisk=False, nowrap=True): diff --git a/contrib/python/psutil/py3/psutil/_common.py b/contrib/python/psutil/py3/psutil/_common.py index 6989feafda..9fd7b0cfb8 100644 --- a/contrib/python/psutil/py3/psutil/_common.py +++ b/contrib/python/psutil/py3/psutil/_common.py @@ -120,7 +120,7 @@ STATUS_WAITING = "waiting" # FreeBSD 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" @@ -189,8 +189,7 @@ sdiskio = namedtuple('sdiskio', ['read_count', 'write_count', 'read_bytes', 'write_bytes', 'read_time', 'write_time']) # psutil.disk_partitions() -sdiskpart = namedtuple('sdiskpart', ['device', 'mountpoint', 'fstype', 'opts', - 'maxfile', 'maxpath']) +sdiskpart = namedtuple('sdiskpart', ['device', 'mountpoint', 'fstype', 'opts']) # psutil.net_io_counters() snetio = namedtuple('snetio', ['bytes_sent', 'bytes_recv', 'packets_sent', 'packets_recv', @@ -243,17 +242,17 @@ pio = namedtuple( 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 # =================================================================== @@ -331,6 +330,9 @@ class NoSuchProcess(Error): self.name = name self.msg = msg or "process no longer exists" + def __reduce__(self): + return (self.__class__, (self.pid, self.name, self.msg)) + class ZombieProcess(NoSuchProcess): """Exception raised when querying a zombie process. This is @@ -347,6 +349,9 @@ class ZombieProcess(NoSuchProcess): self.ppid = ppid self.msg = msg or "PID still exists but it's a zombie" + def __reduce__(self): + return (self.__class__, (self.pid, self.name, self.ppid, self.msg)) + class AccessDenied(Error): """Exception raised when permission to perform an action is denied.""" @@ -359,6 +364,9 @@ class AccessDenied(Error): self.name = name self.msg = msg or "" + def __reduce__(self): + return (self.__class__, (self.pid, self.name, self.msg)) + class TimeoutExpired(Error): """Raised on Process.wait(timeout) if timeout expires and process @@ -374,6 +382,9 @@ class TimeoutExpired(Error): self.name = name self.msg = "timeout after %s seconds" % seconds + def __reduce__(self): + return (self.__class__, (self.seconds, self.pid, self.name)) + # =================================================================== # --- utils @@ -969,7 +980,7 @@ def debug(msg): if PSUTIL_DEBUG: import inspect - fname, lineno, _, lines, index = inspect.getframeinfo( + fname, lineno, _, _lines, _index = inspect.getframeinfo( inspect.currentframe().f_back ) if isinstance(msg, Exception): diff --git a/contrib/python/psutil/py3/psutil/_compat.py b/contrib/python/psutil/py3/psutil/_compat.py index 3db56c6019..6070c2a044 100644 --- a/contrib/python/psutil/py3/psutil/_compat.py +++ b/contrib/python/psutil/py3/psutil/_compat.py @@ -23,7 +23,7 @@ __all__ = [ # builtins "long", "range", "super", "unicode", "basestring", # literals - "u", "b", + "b", # collections module "lru_cache", # shutil module @@ -47,9 +47,6 @@ if PY3: basestring = str range = range - def u(s): - return s - def b(s): return s.encode("latin-1") @@ -59,9 +56,6 @@ else: unicode = unicode basestring = basestring - def u(s): - return unicode(s, "unicode_escape") - def b(s): return s diff --git a/contrib/python/psutil/py3/psutil/_psaix.py b/contrib/python/psutil/py3/psutil/_psaix.py index 7310ab6c3d..f48425eb8a 100644 --- a/contrib/python/psutil/py3/psutil/_psaix.py +++ b/contrib/python/psutil/py3/psutil/_psaix.py @@ -105,7 +105,7 @@ svmem = namedtuple('svmem', ['total', 'available', 'percent', 'used', 'free']) def virtual_memory(): - total, avail, free, pinned, inuse = cext.virtual_mem() + total, avail, free, _pinned, inuse = cext.virtual_mem() percent = usage_percent((total - avail), total, round_=1) return svmem(total, avail, percent, inuse, free) @@ -191,10 +191,7 @@ def disk_partitions(all=False): # filter by filesystem having a total size > 0. if not disk_usage(mountpoint).total: continue - maxfile = maxpath = None # set later - ntuple = _common.sdiskpart( - device, mountpoint, fstype, opts, maxfile, maxpath - ) + ntuple = _common.sdiskpart(device, mountpoint, fstype, opts) retlist.append(ntuple) return retlist @@ -451,7 +448,7 @@ class Process: 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 diff --git a/contrib/python/psutil/py3/psutil/_psbsd.py b/contrib/python/psutil/py3/psutil/_psbsd.py index da68f5efd5..4d49cf98bd 100644 --- a/contrib/python/psutil/py3/psutil/_psbsd.py +++ b/contrib/python/psutil/py3/psutil/_psbsd.py @@ -321,7 +321,7 @@ def cpu_stats(): if FREEBSD: # Note: the C ext is returning some metrics we are not exposing: # traps. - ctxsw, intrs, soft_intrs, syscalls, traps = cext.cpu_stats() + ctxsw, intrs, soft_intrs, syscalls, _traps = cext.cpu_stats() elif NETBSD: # XXX # Note about intrs: the C extension returns 0. intrs @@ -332,7 +332,7 @@ def cpu_stats(): # # Note: the C ext is returning some metrics we are not exposing: # traps, faults and forks. - ctxsw, intrs, soft_intrs, syscalls, traps, faults, forks = ( + ctxsw, intrs, soft_intrs, syscalls, _traps, _faults, _forks = ( cext.cpu_stats() ) with open('/proc/stat', 'rb') as f: @@ -342,7 +342,7 @@ def cpu_stats(): elif OPENBSD: # Note: the C ext is returning some metrics we are not exposing: # traps, faults and forks. - ctxsw, intrs, soft_intrs, syscalls, traps, faults, forks = ( + ctxsw, intrs, soft_intrs, syscalls, _traps, _faults, _forks = ( cext.cpu_stats() ) return _common.scpustats(ctxsw, intrs, soft_intrs, syscalls) @@ -395,10 +395,7 @@ def disk_partitions(all=False): partitions = cext.disk_partitions() for partition in partitions: device, mountpoint, fstype, opts = partition - maxfile = maxpath = None # set later - ntuple = _common.sdiskpart( - device, mountpoint, fstype, opts, maxfile, maxpath - ) + ntuple = _common.sdiskpart(device, mountpoint, fstype, opts) retlist.append(ntuple) return retlist @@ -561,10 +558,9 @@ def pids(): return ret -if OPENBSD or NETBSD: +if NETBSD: def pid_exists(pid): - """Return True if pid exists.""" exists = _psposix.pid_exists(pid) if not exists: # We do this because _psposix.pid_exists() lies in case of @@ -573,7 +569,19 @@ if OPENBSD or NETBSD: else: return True -else: +elif OPENBSD: + + def pid_exists(pid): + exists = _psposix.pid_exists(pid) + if not exists: + return False + else: + # OpenBSD seems to be the only BSD platform where + # _psposix.pid_exists() returns True for thread IDs (tids), + # so we can't use it. + return pid in pids() + +else: # FreeBSD pid_exists = _psposix.pid_exists @@ -813,7 +821,7 @@ class Process: 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" @@ -827,7 +835,7 @@ class Process: 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] diff --git a/contrib/python/psutil/py3/psutil/_pslinux.py b/contrib/python/psutil/py3/psutil/_pslinux.py index bab70b5d20..8e389e49ce 100644 --- a/contrib/python/psutil/py3/psutil/_pslinux.py +++ b/contrib/python/psutil/py3/psutil/_pslinux.py @@ -60,7 +60,6 @@ else: # fmt: off __extra__all__ = [ - # 'PROCFS_PATH', # io prio constants "IOPRIO_CLASS_NONE", "IOPRIO_CLASS_RT", "IOPRIO_CLASS_BE", @@ -421,7 +420,7 @@ def calculate_avail_vmem(mems): def virtual_memory(): """Report virtual memory stats. - This implementation mimicks procps-ng-3.3.12, aka "free" CLI tool: + This implementation mimics procps-ng-3.3.12, aka "free" CLI tool: https://gitlab.com/procps-ng/procps/blob/ 24fd2605c51fccc375ab0287cec33aa767f06718/proc/sysinfo.c#L778-791 The returned values are supposed to match both "free" and "vmstat -s" @@ -783,6 +782,13 @@ if os.path.exists("/sys/devices/system/cpu/cpufreq/policy0") or os.path.exists( # https://github.com/giampaolo/psutil/issues/1071 curr = bcat(pjoin(path, "cpuinfo_cur_freq"), fallback=None) if curr is None: + online_path = ( + "/sys/devices/system/cpu/cpu{}/online".format(i) + ) + # if cpu core is offline, set to all zeroes + if cat(online_path, fallback=None) == "0\n": + ret.append(_common.scpufreq(0.0, 0.0, 0.0)) + continue msg = "can't find current frequency file" raise NotImplementedError(msg) curr = int(curr) / 1000 @@ -812,7 +818,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". @@ -978,8 +984,8 @@ class Connections: 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) @@ -1056,12 +1062,12 @@ class Connections: 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(): @@ -1077,25 +1083,25 @@ def net_io_counters(): name = line[:colon].strip() fields = line[colon + 1 :].strip().split() - # in ( + # in bytes_recv, packets_recv, errin, dropin, - fifoin, # unused - framein, # unused - compressedin, # unused - multicastin, # unused + _fifoin, # unused + _framein, # unused + _compressedin, # unused + _multicastin, # unused # out bytes_sent, packets_sent, errout, dropout, - fifoout, # unused - collisionsout, # unused - carrierout, # unused - compressedout, + _fifoout, # unused + _collisionsout, # unused + _carrierout, # unused + _compressedout, # unused ) = map(int, fields) retdict[name] = ( @@ -1358,12 +1364,9 @@ def disk_partitions(all=False): if device in ("/dev/root", "rootfs"): device = RootFsDeviceFinder().find() or device if not all: - if device == '' or fstype not in fstypes: + if not device or fstype not in fstypes: continue - maxfile = maxpath = None # set later - ntuple = _common.sdiskpart( - device, mountpoint, fstype, opts, maxfile, maxpath - ) + ntuple = _common.sdiskpart(device, mountpoint, fstype, opts) retlist.append(ntuple) return retlist @@ -2091,9 +2094,9 @@ class Process: for header, data in get_blocks(lines, current_block): hfields = header.split(None, 5) try: - addr, perms, offset, dev, inode, path = hfields + addr, perms, _offset, _dev, _inode, path = hfields except ValueError: - addr, perms, offset, dev, inode, path = hfields + [''] + addr, perms, _offset, _dev, _inode, path = hfields + [''] if not path: path = '[anon]' else: @@ -2104,7 +2107,7 @@ class Process: path ): path = path[:-10] - ls.append(( + item = ( decode(addr), decode(perms), path, @@ -2118,7 +2121,8 @@ class Process: data.get(b'Referenced:', 0), data.get(b'Anonymous:', 0), data.get(b'Swap:', 0), - )) + ) + ls.append(item) return ls @wrap_exceptions @@ -2343,8 +2347,8 @@ class Process: 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 diff --git a/contrib/python/psutil/py3/psutil/_psosx.py b/contrib/python/psutil/py3/psutil/_psosx.py index 673ac0db75..41263fd735 100644 --- a/contrib/python/psutil/py3/psutil/_psosx.py +++ b/contrib/python/psutil/py3/psutil/_psosx.py @@ -165,7 +165,7 @@ def cpu_count_cores(): def cpu_stats(): - ctx_switches, interrupts, soft_interrupts, syscalls, traps = ( + ctx_switches, interrupts, soft_interrupts, syscalls, _traps = ( cext.cpu_stats() ) return _common.scpustats( @@ -203,10 +203,7 @@ def disk_partitions(all=False): if not all: if not os.path.isabs(device) or not os.path.exists(device): continue - maxfile = maxpath = None # set later - ntuple = _common.sdiskpart( - device, mountpoint, fstype, opts, maxfile, maxpath - ) + ntuple = _common.sdiskpart(device, mountpoint, fstype, opts) retlist.append(ntuple) return retlist @@ -249,7 +246,7 @@ def net_connections(kind='inet'): ret = [] for pid in pids(): try: - cons = Process(pid).connections(kind) + cons = Process(pid).net_connections(kind) except NoSuchProcess: continue else: @@ -504,14 +501,14 @@ class Process: return files @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" % (kind, ', '.join([repr(x) for x in conn_tmap])) ) families, types = conn_tmap[kind] - rawlist = cext.proc_connections(self.pid, families, types) + rawlist = cext.proc_net_connections(self.pid, families, types) ret = [] for item in rawlist: fd, fam, type, laddr, raddr, status = item diff --git a/contrib/python/psutil/py3/psutil/_pssunos.py b/contrib/python/psutil/py3/psutil/_pssunos.py index dddbece1f3..1c0b96e9e9 100644 --- a/contrib/python/psutil/py3/psutil/_pssunos.py +++ b/contrib/python/psutil/py3/psutil/_pssunos.py @@ -209,7 +209,7 @@ def cpu_count_cores(): def cpu_stats(): """Return various CPU stats as a named tuple.""" - ctx_switches, interrupts, syscalls, traps = cext.cpu_stats() + ctx_switches, interrupts, syscalls, _traps = cext.cpu_stats() soft_interrupts = 0 return _common.scpustats( ctx_switches, interrupts, soft_interrupts, syscalls @@ -246,10 +246,7 @@ def disk_partitions(all=False): # https://github.com/giampaolo/psutil/issues/1674 debug("skipping %r: %s" % (mountpoint, err)) continue - maxfile = maxpath = None # set later - ntuple = _common.sdiskpart( - device, mountpoint, fstype, opts, maxfile, maxpath - ) + ntuple = _common.sdiskpart(device, mountpoint, fstype, opts) retlist.append(ntuple) return retlist @@ -669,7 +666,7 @@ class Process: yield (-1, socket.AF_UNIX, type, path, "", _common.CONN_NONE) @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 @@ -730,7 +727,7 @@ class Process: # readlink() even if it exists (ls shows it). # If that's the case we just return the # unresolved link path. - # This seems an incosistency with /proc similar + # This seems an inconsistency with /proc similar # to: http://goo.gl/55XgO name = '%s/%s/path/%s' % (procfs_path, self.pid, name) hit_enoent = True diff --git a/contrib/python/psutil/py3/psutil/_psutil_osx.c b/contrib/python/psutil/py3/psutil/_psutil_osx.c index 369fbbfb48..4aa11d1700 100644 --- a/contrib/python/psutil/py3/psutil/_psutil_osx.c +++ b/contrib/python/psutil/py3/psutil/_psutil_osx.c @@ -23,7 +23,7 @@ static PyMethodDef mod_methods[] = { // --- per-process functions {"proc_cmdline", psutil_proc_cmdline, METH_VARARGS}, - {"proc_connections", psutil_proc_connections, METH_VARARGS}, + {"proc_net_connections", psutil_proc_net_connections, METH_VARARGS}, {"proc_cwd", psutil_proc_cwd, METH_VARARGS}, {"proc_environ", psutil_proc_environ, METH_VARARGS}, {"proc_exe", psutil_proc_exe, METH_VARARGS}, diff --git a/contrib/python/psutil/py3/psutil/_pswindows.py b/contrib/python/psutil/py3/psutil/_pswindows.py index 2d3a0c9fdb..0ba511b901 100644 --- a/contrib/python/psutil/py3/psutil/_pswindows.py +++ b/contrib/python/psutil/py3/psutil/_pswindows.py @@ -238,8 +238,7 @@ def getpagesize(): def virtual_memory(): """System virtual memory as a namedtuple.""" mem = cext.virtual_mem() - totphys, availphys, totsys, availsys = mem - # + totphys, availphys, _totsys, _availsys = mem total = totphys avail = availphys free = availphys @@ -338,7 +337,7 @@ def cpu_count_cores(): def cpu_stats(): """Return CPU statistics.""" - ctx_switches, interrupts, dpcs, syscalls = cext.cpu_stats() + ctx_switches, interrupts, _dpcs, syscalls = cext.cpu_stats() soft_interrupts = 0 return _common.scpustats( ctx_switches, interrupts, soft_interrupts, syscalls @@ -515,7 +514,7 @@ def win_service_get(name): return service -class WindowsService: +class WindowsService: # noqa: PLW1641 """Represents an installed Windows service.""" def __init__(self, name, display_name): @@ -703,12 +702,10 @@ def is_permission_err(exc): # On Python 2 OSError doesn't always have 'winerror'. Sometimes # it does, in which case the original exception was WindowsError # (which is a subclass of OSError). - if getattr(exc, "winerror", -1) in ( + return getattr(exc, "winerror", -1) in ( cext.ERROR_ACCESS_DENIED, cext.ERROR_PRIVILEGE_NOT_HELD, - ): - return True - return False + ) def convert_oserror(exc, pid=None, name=None): @@ -865,6 +862,7 @@ class Process: if is_permission_err(err): # TODO: the C ext can probably be refactored in order # to get this from cext.proc_info() + debug("attempting memory_info() fallback (slower)") info = self._proc_info() return ( info[pinfo_map['num_page_faults']], @@ -988,10 +986,11 @@ class Process: # Note: proc_times() not put under oneshot() 'cause create_time() # is already cached by the main Process class. try: - user, system, created = cext.proc_times(self.pid) + _user, _system, created = cext.proc_times(self.pid) return created except OSError as err: if is_permission_err(err): + debug("attempting create_time() fallback (slower)") return self._proc_info()[pinfo_map['create_time']] raise @@ -1011,10 +1010,11 @@ class Process: @wrap_exceptions def cpu_times(self): try: - user, system, created = cext.proc_times(self.pid) + user, system, _created = cext.proc_times(self.pid) except OSError as err: if not is_permission_err(err): raise + debug("attempting cpu_times() fallback (slower)") info = self._proc_info() user = info[pinfo_map['user_time']] system = info[pinfo_map['kernel_time']] @@ -1059,7 +1059,7 @@ class Process: return list(ret) @wrap_exceptions - def connections(self, kind='inet'): + def net_connections(self, kind='inet'): return net_connections(kind, _pid=self.pid) @wrap_exceptions @@ -1101,6 +1101,7 @@ class Process: except OSError as err: if not is_permission_err(err): raise + debug("attempting io_counters() fallback (slower)") info = self._proc_info() ret = ( info[pinfo_map['io_rcount']], @@ -1160,6 +1161,7 @@ class Process: return cext.proc_num_handles(self.pid) except OSError as err: if is_permission_err(err): + debug("attempting num_handles() fallback (slower)") return self._proc_info()[pinfo_map['num_handles']] raise diff --git a/contrib/python/psutil/py3/psutil/arch/osx/disk.c b/contrib/python/psutil/py3/psutil/arch/osx/disk.c index 961fc42a48..d02cf794d5 100644 --- a/contrib/python/psutil/py3/psutil/arch/osx/disk.c +++ b/contrib/python/psutil/py3/psutil/arch/osx/disk.c @@ -86,8 +86,6 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { strlcat(opts, ",async", sizeof(opts)); if (flags & MNT_EXPORTED) strlcat(opts, ",exported", sizeof(opts)); - if (flags & MNT_QUARANTINE) - strlcat(opts, ",quarantine", sizeof(opts)); if (flags & MNT_LOCAL) strlcat(opts, ",local", sizeof(opts)); if (flags & MNT_QUOTA) @@ -108,10 +106,6 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { strlcat(opts, ",nouserxattr", sizeof(opts)); if (flags & MNT_DEFWRITE) strlcat(opts, ",defwrite", sizeof(opts)); - if (flags & MNT_MULTILABEL) - strlcat(opts, ",multilabel", sizeof(opts)); - if (flags & MNT_NOATIME) - strlcat(opts, ",noatime", sizeof(opts)); if (flags & MNT_UPDATE) strlcat(opts, ",update", sizeof(opts)); if (flags & MNT_RELOAD) @@ -120,7 +114,19 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { strlcat(opts, ",force", sizeof(opts)); if (flags & MNT_CMDFLAGS) strlcat(opts, ",cmdflags", sizeof(opts)); - + // requires macOS >= 10.5 +#ifdef MNT_QUARANTINE + if (flags & MNT_QUARANTINE) + strlcat(opts, ",quarantine", sizeof(opts)); +#endif +#ifdef MNT_MULTILABEL + if (flags & MNT_MULTILABEL) + strlcat(opts, ",multilabel", sizeof(opts)); +#endif +#ifdef MNT_NOATIME + if (flags & MNT_NOATIME) + strlcat(opts, ",noatime", sizeof(opts)); +#endif py_dev = PyUnicode_DecodeFSDefault(fs[i].f_mntfromname); if (! py_dev) goto error; diff --git a/contrib/python/psutil/py3/psutil/arch/osx/net.c b/contrib/python/psutil/py3/psutil/arch/osx/net.c index e9cc61e9b1..d365676ce1 100644 --- a/contrib/python/psutil/py3/psutil/arch/osx/net.c +++ b/contrib/python/psutil/py3/psutil/arch/osx/net.c @@ -9,11 +9,11 @@ // https://github.com/giampaolo/psutil/blame/efd7ed3/psutil/_psutil_osx.c #include <Python.h> -#include <net/if_dl.h> -#include <net/route.h> -#include <sys/sysctl.h> #include <sys/socket.h> +#include <sys/sysctl.h> #include <net/if.h> +#include <net/if_dl.h> +#include <net/route.h> #include "../../_psutil_common.h" diff --git a/contrib/python/psutil/py3/psutil/arch/osx/proc.c b/contrib/python/psutil/py3/psutil/arch/osx/proc.c index 6f66c8613f..2cdb9911c0 100644 --- a/contrib/python/psutil/py3/psutil/arch/osx/proc.c +++ b/contrib/python/psutil/py3/psutil/arch/osx/proc.c @@ -857,7 +857,7 @@ error: * - /usr/include/sys/proc_info.h */ PyObject * -psutil_proc_connections(PyObject *self, PyObject *args) { +psutil_proc_net_connections(PyObject *self, PyObject *args) { pid_t pid; int num_fds; int i; diff --git a/contrib/python/psutil/py3/psutil/arch/osx/proc.h b/contrib/python/psutil/py3/psutil/arch/osx/proc.h index 63f16ccdd2..f18f5f1fd6 100644 --- a/contrib/python/psutil/py3/psutil/arch/osx/proc.h +++ b/contrib/python/psutil/py3/psutil/arch/osx/proc.h @@ -8,13 +8,13 @@ PyObject *psutil_pids(PyObject *self, PyObject *args); PyObject *psutil_proc_cmdline(PyObject *self, PyObject *args); -PyObject *psutil_proc_connections(PyObject *self, PyObject *args); PyObject *psutil_proc_cwd(PyObject *self, PyObject *args); PyObject *psutil_proc_environ(PyObject *self, PyObject *args); PyObject *psutil_proc_exe(PyObject *self, PyObject *args); PyObject *psutil_proc_kinfo_oneshot(PyObject *self, PyObject *args); PyObject *psutil_proc_memory_uss(PyObject *self, PyObject *args); PyObject *psutil_proc_name(PyObject *self, PyObject *args); +PyObject *psutil_proc_net_connections(PyObject *self, PyObject *args); PyObject *psutil_proc_num_fds(PyObject *self, PyObject *args); PyObject *psutil_proc_open_files(PyObject *self, PyObject *args); PyObject *psutil_proc_pidtaskinfo_oneshot(PyObject *self, PyObject *args); diff --git a/contrib/python/psutil/py3/psutil/arch/osx/sensors.c b/contrib/python/psutil/py3/psutil/arch/osx/sensors.c index a2faa157c4..53626c2dc4 100644 --- a/contrib/python/psutil/py3/psutil/arch/osx/sensors.c +++ b/contrib/python/psutil/py3/psutil/arch/osx/sensors.c @@ -12,6 +12,7 @@ #include <Python.h> +#include <CoreFoundation/CoreFoundation.h> #include <IOKit/ps/IOPowerSources.h> #include <IOKit/ps/IOPSKeys.h> @@ -59,7 +60,7 @@ psutil_sensors_battery(PyObject *self, PyObject *args) { power_sources_information, CFSTR(kIOPSCurrentCapacityKey)); if (!CFNumberGetValue(capacity_ref, kCFNumberSInt32Type, &capacity)) { PyErr_SetString(PyExc_RuntimeError, - "No battery capacity infomration in power sources info"); + "No battery capacity information in power sources info"); goto error; } diff --git a/contrib/python/psutil/py3/psutil/arch/windows/disk.c b/contrib/python/psutil/py3/psutil/arch/windows/disk.c index e72e3a7554..88469e3a61 100644 --- a/contrib/python/psutil/py3/psutil/arch/windows/disk.c +++ b/contrib/python/psutil/py3/psutil/arch/windows/disk.c @@ -319,13 +319,11 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { strcat_s(mp_path, _countof(mp_path), mp_buf); py_tuple = Py_BuildValue( - "(ssssIi)", + "(ssss)", drive_letter, mp_path, fs_type, // typically "NTFS" - opts, - lpMaximumComponentLength, // max file length - MAX_PATH // max path length + opts ); if (!py_tuple || @@ -351,13 +349,11 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { strcat_s(opts, _countof(opts), psutil_get_drive_type(type)); py_tuple = Py_BuildValue( - "(ssssIi)", + "(ssss)", drive_letter, drive_letter, fs_type, // either FAT, FAT32, NTFS, HPFS, CDFS, UDF or NWFS - opts, - lpMaximumComponentLength, // max file length - MAX_PATH // max path length + opts ); if (!py_tuple) goto error; diff --git a/contrib/python/psutil/py3/psutil/arch/windows/proc_utils.c b/contrib/python/psutil/py3/psutil/arch/windows/proc_utils.c index dac1129c0f..77b6dbf1e8 100644 --- a/contrib/python/psutil/py3/psutil/arch/windows/proc_utils.c +++ b/contrib/python/psutil/py3/psutil/arch/windows/proc_utils.c @@ -173,17 +173,15 @@ psutil_pid_is_running(DWORD pid) { hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid); - // Access denied means there's a process to deny access to. - if ((hProcess == NULL) && (GetLastError() == ERROR_ACCESS_DENIED)) - return 1; - - hProcess = psutil_check_phandle(hProcess, pid, 1); if (hProcess != NULL) { + hProcess = psutil_check_phandle(hProcess, pid, 1); + if (hProcess != NULL) { + CloseHandle(hProcess); + return 1; + } CloseHandle(hProcess); - return 1; } - CloseHandle(hProcess); PyErr_Clear(); return psutil_pid_in_pids(pid); } diff --git a/contrib/python/psutil/py3/ya.make b/contrib/python/psutil/py3/ya.make index 2177ad09c8..ec62842832 100644 --- a/contrib/python/psutil/py3/ya.make +++ b/contrib/python/psutil/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(5.9.8) +VERSION(6.0.0) LICENSE(BSD-3-Clause) @@ -27,7 +27,7 @@ NO_CHECK_IMPORTS( NO_UTIL() CFLAGS( - -DPSUTIL_VERSION=598 + -DPSUTIL_VERSION=600 ) SRCS( |