Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- mplug_owl2/lib/python3.10/site-packages/aiosignal/__init__.py +36 -0
- mplug_owl2/lib/python3.10/site-packages/aiosignal/__init__.pyi +12 -0
- mplug_owl2/lib/python3.10/site-packages/aiosignal/py.typed +0 -0
- mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/INSTALLER +1 -0
- mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/LICENSE +21 -0
- mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/METADATA +172 -0
- mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/RECORD +25 -0
- mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/REQUESTED +0 -0
- mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/WHEEL +4 -0
- mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/entry_points.txt +4 -0
- mplug_owl2/lib/python3.10/site-packages/linkify_it/__init__.py +4 -0
- mplug_owl2/lib/python3.10/site-packages/linkify_it/__pycache__/__init__.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/linkify_it/__pycache__/main.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/linkify_it/__pycache__/tlds.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/linkify_it/__pycache__/ucre.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/linkify_it/main.py +642 -0
- mplug_owl2/lib/python3.10/site-packages/linkify_it/tlds.py +1517 -0
- mplug_owl2/lib/python3.10/site-packages/linkify_it/ucre.py +264 -0
- mplug_owl2/lib/python3.10/site-packages/nvidia_cufft_cu12-11.2.1.3.dist-info/RECORD +21 -0
- mplug_owl2/lib/python3.10/site-packages/nvidia_cufft_cu12-11.2.1.3.dist-info/REQUESTED +0 -0
- mplug_owl2/lib/python3.10/site-packages/nvidia_cufft_cu12-11.2.1.3.dist-info/WHEEL +5 -0
- mplug_owl2/lib/python3.10/site-packages/nvidia_cufft_cu12-11.2.1.3.dist-info/top_level.txt +1 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__init__.py +2486 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/__init__.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_common.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_compat.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_psaix.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_psbsd.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_pslinux.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_psosx.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_psposix.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_pssunos.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_pswindows.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/_psbsd.py +985 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/_pslinux.py +2379 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/_psosx.py +552 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/_psutil_linux.abi3.so +3 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/_psutil_posix.abi3.so +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/tests/__pycache__/test_contracts.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/tests/__pycache__/test_process.cpython-310.pyc +0 -0
- mplug_owl2/lib/python3.10/site-packages/psutil/tests/__pycache__/test_process_all.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0021.rst +21 -0
- openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0043.rst +47 -0
- openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0049.rst +24 -0
- openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0052.rst +28 -0
- openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0054.rst +53 -0
- openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0058.rst +115 -0
- openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0081.rst +24 -0
- openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0111.rst +27 -0
.gitattributes
CHANGED
|
@@ -716,3 +716,4 @@ mplug_owl2/lib/python3.10/site-packages/pygments/lexers/__pycache__/lisp.cpython
|
|
| 716 |
mplug_owl2/lib/python3.10/site-packages/nvidia/cuda_cupti/lib/libcupti.so.12 filter=lfs diff=lfs merge=lfs -text
|
| 717 |
mplug_owl2/lib/python3.10/site-packages/nvidia/cuda_cupti/lib/libcupti.so.11.7 filter=lfs diff=lfs merge=lfs -text
|
| 718 |
mplug_owl2/lib/python3.10/site-packages/nvidia/cudnn/lib/libcudnn_heuristic.so.9 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 716 |
mplug_owl2/lib/python3.10/site-packages/nvidia/cuda_cupti/lib/libcupti.so.12 filter=lfs diff=lfs merge=lfs -text
|
| 717 |
mplug_owl2/lib/python3.10/site-packages/nvidia/cuda_cupti/lib/libcupti.so.11.7 filter=lfs diff=lfs merge=lfs -text
|
| 718 |
mplug_owl2/lib/python3.10/site-packages/nvidia/cudnn/lib/libcudnn_heuristic.so.9 filter=lfs diff=lfs merge=lfs -text
|
| 719 |
+
mplug_owl2/lib/python3.10/site-packages/psutil/_psutil_linux.abi3.so filter=lfs diff=lfs merge=lfs -text
|
mplug_owl2/lib/python3.10/site-packages/aiosignal/__init__.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from frozenlist import FrozenList
|
| 2 |
+
|
| 3 |
+
__version__ = "1.3.2"
|
| 4 |
+
|
| 5 |
+
__all__ = ("Signal",)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class Signal(FrozenList):
|
| 9 |
+
"""Coroutine-based signal implementation.
|
| 10 |
+
|
| 11 |
+
To connect a callback to a signal, use any list method.
|
| 12 |
+
|
| 13 |
+
Signals are fired using the send() coroutine, which takes named
|
| 14 |
+
arguments.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
__slots__ = ("_owner",)
|
| 18 |
+
|
| 19 |
+
def __init__(self, owner):
|
| 20 |
+
super().__init__()
|
| 21 |
+
self._owner = owner
|
| 22 |
+
|
| 23 |
+
def __repr__(self):
|
| 24 |
+
return "<Signal owner={}, frozen={}, {!r}>".format(
|
| 25 |
+
self._owner, self.frozen, list(self)
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
async def send(self, *args, **kwargs):
|
| 29 |
+
"""
|
| 30 |
+
Sends data to all registered receivers.
|
| 31 |
+
"""
|
| 32 |
+
if not self.frozen:
|
| 33 |
+
raise RuntimeError("Cannot send non-frozen signal.")
|
| 34 |
+
|
| 35 |
+
for receiver in self:
|
| 36 |
+
await receiver(*args, **kwargs) # type: ignore
|
mplug_owl2/lib/python3.10/site-packages/aiosignal/__init__.pyi
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Generic, TypeVar
|
| 2 |
+
|
| 3 |
+
from frozenlist import FrozenList
|
| 4 |
+
|
| 5 |
+
__all__ = ("Signal",)
|
| 6 |
+
|
| 7 |
+
_T = TypeVar("_T")
|
| 8 |
+
|
| 9 |
+
class Signal(FrozenList[_T], Generic[_T]):
|
| 10 |
+
def __init__(self, owner: Any) -> None: ...
|
| 11 |
+
def __repr__(self) -> str: ...
|
| 12 |
+
async def send(self, *args: Any, **kwargs: Any) -> None: ...
|
mplug_owl2/lib/python3.10/site-packages/aiosignal/py.typed
ADDED
|
File without changes
|
mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2016 Ronie Martinez
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: latex2mathml
|
| 3 |
+
Version: 3.77.0
|
| 4 |
+
Summary: Pure Python library for LaTeX to MathML conversion
|
| 5 |
+
Home-page: https://github.com/roniemartinez/latex2mathml
|
| 6 |
+
License: MIT
|
| 7 |
+
Keywords: latex,mathml
|
| 8 |
+
Author: Ronie Martinez
|
| 9 |
+
Author-email: ronmarti18@gmail.com
|
| 10 |
+
Requires-Python: >=3.8.1,<4.0.0
|
| 11 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 12 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 13 |
+
Classifier: Programming Language :: Python :: 3
|
| 14 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 15 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 19 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 20 |
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
| 21 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 22 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
| 23 |
+
Classifier: Topic :: Text Processing :: Markup :: LaTeX
|
| 24 |
+
Project-URL: Donate, https://www.buymeacoffee.com/roniemartinez
|
| 25 |
+
Project-URL: Repository, https://github.com/roniemartinez/latex2mathml
|
| 26 |
+
Description-Content-Type: text/markdown
|
| 27 |
+
|
| 28 |
+
<table>
|
| 29 |
+
<tr>
|
| 30 |
+
<td>License</td>
|
| 31 |
+
<td><img src='https://img.shields.io/pypi/l/latex2mathml.svg?style=for-the-badge' alt="License"></td>
|
| 32 |
+
<td>Version</td>
|
| 33 |
+
<td><img src='https://img.shields.io/pypi/v/latex2mathml.svg?logo=pypi&style=for-the-badge' alt="Version"></td>
|
| 34 |
+
</tr>
|
| 35 |
+
<tr>
|
| 36 |
+
<td>Github Actions</td>
|
| 37 |
+
<td><img src='https://img.shields.io/github/actions/workflow/status/roniemartinez/latex2mathml/python.yml?branch=master&label=actions&logo=github%20actions&style=for-the-badge' alt="Github Actions"></td>
|
| 38 |
+
<td>Coverage</td>
|
| 39 |
+
<td><img src='https://img.shields.io/codecov/c/github/roniemartinez/latex2mathml/master?label=codecov&logo=codecov&style=for-the-badge' alt="CodeCov"></td>
|
| 40 |
+
</tr>
|
| 41 |
+
<tr>
|
| 42 |
+
<td>Supported versions</td>
|
| 43 |
+
<td><img src='https://img.shields.io/pypi/pyversions/latex2mathml.svg?logo=python&style=for-the-badge' alt="Python Versions"></td>
|
| 44 |
+
<td>Wheel</td>
|
| 45 |
+
<td><img src='https://img.shields.io/pypi/wheel/latex2mathml.svg?style=for-the-badge' alt="Wheel"></td>
|
| 46 |
+
</tr>
|
| 47 |
+
<tr>
|
| 48 |
+
<td>Status</td>
|
| 49 |
+
<td><img src='https://img.shields.io/pypi/status/latex2mathml.svg?style=for-the-badge' alt="Status"></td>
|
| 50 |
+
<td>Downloads</td>
|
| 51 |
+
<td><img src='https://img.shields.io/pypi/dm/latex2mathml.svg?style=for-the-badge' alt="Downloads"></td>
|
| 52 |
+
</tr>
|
| 53 |
+
<tr>
|
| 54 |
+
<td>All Contributors</td>
|
| 55 |
+
<td><a href="#contributors-"><img src='https://img.shields.io/github/all-contributors/roniemartinez/latex2mathml?style=for-the-badge' alt="All Contributors"></a></td>
|
| 56 |
+
</tr>
|
| 57 |
+
</table>
|
| 58 |
+
|
| 59 |
+
# latex2mathml
|
| 60 |
+
|
| 61 |
+
Pure Python library for LaTeX to MathML conversion
|
| 62 |
+
|
| 63 |
+
## Installation
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
pip install latex2mathml
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Usage
|
| 70 |
+
|
| 71 |
+
### Python
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
import latex2mathml.converter
|
| 75 |
+
|
| 76 |
+
latex_input = "<your_latex_string>"
|
| 77 |
+
mathml_output = latex2mathml.converter.convert(latex_input)
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### Command-line
|
| 81 |
+
|
| 82 |
+
```shell
|
| 83 |
+
% latex2mathml -h
|
| 84 |
+
usage: latex2mathml [-h] [-V] [-b] [-t TEXT | -f FILE | -s]
|
| 85 |
+
|
| 86 |
+
Pure Python library for LaTeX to MathML conversion
|
| 87 |
+
|
| 88 |
+
options:
|
| 89 |
+
-h, --help show this help message and exit
|
| 90 |
+
-V, --version Show version
|
| 91 |
+
-b, --block Display block
|
| 92 |
+
|
| 93 |
+
required arguments:
|
| 94 |
+
-t TEXT, --text TEXT Text
|
| 95 |
+
-f FILE, --file FILE File
|
| 96 |
+
-s, --stdin Stdin
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
## References
|
| 100 |
+
### LaTeX
|
| 101 |
+
|
| 102 |
+
- https://en.wikibooks.org/wiki/LaTeX/Mathematics
|
| 103 |
+
- http://artofproblemsolving.com/wiki/index.php?title=Main_Page
|
| 104 |
+
- http://milde.users.sourceforge.net/LUCR/Math/
|
| 105 |
+
- https://math-linux.com/latex-26/faq/latex-faq/article/latex-derivatives-limits-sums-products-and-integrals
|
| 106 |
+
- https://www.tutorialspoint.com/tex_commands
|
| 107 |
+
- https://www.giss.nasa.gov/tools/latex/ltx-86.html
|
| 108 |
+
- https://ftp.gwdg.de/pub/ctan/info/l2tabu/english/l2tabuen.pdf
|
| 109 |
+
|
| 110 |
+
### MathML
|
| 111 |
+
|
| 112 |
+
- http://www.xmlmind.com/tutorials/MathML/
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
## Author
|
| 116 |
+
|
| 117 |
+
- [Ronie Martinez](mailto:ronmarti18@gmail.com)
|
| 118 |
+
|
| 119 |
+
## Contributors ✨
|
| 120 |
+
|
| 121 |
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
| 122 |
+
|
| 123 |
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
| 124 |
+
<!-- prettier-ignore-start -->
|
| 125 |
+
<!-- markdownlint-disable -->
|
| 126 |
+
<table>
|
| 127 |
+
<tbody>
|
| 128 |
+
<tr>
|
| 129 |
+
<td align="center" valign="top" width="14.28%"><a href="https://ron.sh"><img src="https://avatars.githubusercontent.com/u/2573537?v=4?s=100" width="100px;" alt="Ronie Martinez"/><br /><sub><b>Ronie Martinez</b></sub></a><br /><a href="#maintenance-roniemartinez" title="Maintenance">🚧</a> <a href="https://github.com/roniemartinez/latex2mathml/commits?author=roniemartinez" title="Code">💻</a> <a href="#infra-roniemartinez" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
|
| 130 |
+
<td align="center" valign="top" width="14.28%"><a href="https://anwen.cc/"><img src="https://avatars.githubusercontent.com/u/1472850?v=4?s=100" width="100px;" alt="askender"/><br /><sub><b>askender</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/commits?author=askender" title="Documentation">📖</a></td>
|
| 131 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/06180339"><img src="https://avatars.githubusercontent.com/u/25408501?v=4?s=100" width="100px;" alt="06180339"/><br /><sub><b>06180339</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/commits?author=06180339" title="Code">💻</a></td>
|
| 132 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chaihahaha"><img src="https://avatars.githubusercontent.com/u/24356676?v=4?s=100" width="100px;" alt="chaihahaha"/><br /><sub><b>chaihahaha</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/commits?author=chaihahaha" title="Code">💻</a></td>
|
| 133 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/huangradio"><img src="https://avatars.githubusercontent.com/u/63624395?v=4?s=100" width="100px;" alt="HQY"/><br /><sub><b>HQY</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Ahuangradio" title="Bug reports">🐛</a></td>
|
| 134 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Sun-ZhenXing"><img src="https://avatars.githubusercontent.com/u/44517244?v=4?s=100" width="100px;" alt="鸭梨"/><br /><sub><b>鸭梨</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3ASun-ZhenXing" title="Bug reports">🐛</a></td>
|
| 135 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/oliverstefanov"><img src="https://avatars.githubusercontent.com/u/33491656?v=4?s=100" width="100px;" alt="oliverstefanov"/><br /><sub><b>oliverstefanov</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Aoliverstefanov" title="Bug reports">🐛</a></td>
|
| 136 |
+
</tr>
|
| 137 |
+
<tr>
|
| 138 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ghost"><img src="https://avatars.githubusercontent.com/u/10137?v=4?s=100" width="100px;" alt="Deleted user"/><br /><sub><b>Deleted user</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Aghost" title="Bug reports">🐛</a></td>
|
| 139 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/cesaryuan"><img src="https://avatars.githubusercontent.com/u/35998162?v=4?s=100" width="100px;" alt="Cesaryuan"/><br /><sub><b>Cesaryuan</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Acesaryuan" title="Bug reports">🐛</a></td>
|
| 140 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tonystank3000"><img src="https://avatars.githubusercontent.com/u/6315974?v=4?s=100" width="100px;" alt="TonyStank"/><br /><sub><b>TonyStank</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Atonystank3000" title="Bug reports">🐛</a></td>
|
| 141 |
+
<td align="center" valign="top" width="14.28%"><a href="https://polarwinkel.de"><img src="https://avatars.githubusercontent.com/u/1512713?v=4?s=100" width="100px;" alt="Dirk Winkel"/><br /><sub><b>Dirk Winkel</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Apolarwinkel" title="Bug reports">🐛</a></td>
|
| 142 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sinslu"><img src="https://avatars.githubusercontent.com/u/12248270?v=4?s=100" width="100px;" alt="sinslu"/><br /><sub><b>sinslu</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Asinslu" title="Bug reports">🐛</a></td>
|
| 143 |
+
<td align="center" valign="top" width="14.28%"><a href="https://ubavic.rs"><img src="https://avatars.githubusercontent.com/u/53820106?v=4?s=100" width="100px;" alt="Nikola Ubavić"/><br /><sub><b>Nikola Ubavić</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Aubavic" title="Bug reports">🐛</a></td>
|
| 144 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/abhisheksia"><img src="https://avatars.githubusercontent.com/u/68808662?v=4?s=100" width="100px;" alt="abhisheksia"/><br /><sub><b>abhisheksia</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Aabhisheksia" title="Bug reports">🐛</a></td>
|
| 145 |
+
</tr>
|
| 146 |
+
<tr>
|
| 147 |
+
<td align="center" valign="top" width="14.28%"><a href="http://denissalem.tuxfamily.org"><img src="https://avatars.githubusercontent.com/u/4476506?v=4?s=100" width="100px;" alt="Denis Salem"/><br /><sub><b>Denis Salem</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3ADenisSalem" title="Bug reports">🐛</a> <a href="https://github.com/roniemartinez/latex2mathml/commits?author=DenisSalem" title="Code">💻</a></td>
|
| 148 |
+
<td align="center" valign="top" width="14.28%"><a href="https://clontz.org"><img src="https://avatars.githubusercontent.com/u/1559632?v=4?s=100" width="100px;" alt="Steven Clontz"/><br /><sub><b>Steven Clontz</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3AStevenClontz" title="Bug reports">🐛</a></td>
|
| 149 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yuwenjun1"><img src="https://avatars.githubusercontent.com/u/43265090?v=4?s=100" width="100px;" alt="空白"/><br /><sub><b>空白</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Ayuwenjun1" title="Bug reports">🐛</a></td>
|
| 150 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/amuramatsu"><img src="https://avatars.githubusercontent.com/u/6500918?v=4?s=100" width="100px;" alt="MURAMATSU Atshshi"/><br /><sub><b>MURAMATSU Atshshi</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Aamuramatsu" title="Bug reports">🐛</a></td>
|
| 151 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/leingang"><img src="https://avatars.githubusercontent.com/u/570942?v=4?s=100" width="100px;" alt="leingang"/><br /><sub><b>leingang</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Aleingang" title="Bug reports">🐛</a></td>
|
| 152 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Nigel-Amers"><img src="https://avatars.githubusercontent.com/u/14248498?v=4?s=100" width="100px;" alt="Nigel Amers"/><br /><sub><b>Nigel Amers</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3ANigel-Amers" title="Bug reports">🐛</a></td>
|
| 153 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/retsyo"><img src="https://avatars.githubusercontent.com/u/7960913?v=4?s=100" width="100px;" alt="retsyo"/><br /><sub><b>retsyo</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Aretsyo" title="Bug reports">🐛</a></td>
|
| 154 |
+
</tr>
|
| 155 |
+
<tr>
|
| 156 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/miakramer"><img src="https://avatars.githubusercontent.com/u/16845265?v=4?s=100" width="100px;" alt="Mia Kramer"/><br /><sub><b>Mia Kramer</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/commits?author=miakramer" title="Code">💻</a> <a href="https://github.com/roniemartinez/latex2mathml/commits?author=miakramer" title="Documentation">📖</a></td>
|
| 157 |
+
<td align="center" valign="top" width="14.28%"><a href="http://cnx.gdn"><img src="https://avatars.githubusercontent.com/u/13689192?v=4?s=100" width="100px;" alt="Nguyễn Gia Phong"/><br /><sub><b>Nguyễn Gia Phong</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3AMcSinyx" title="Bug reports">🐛</a> <a href="https://github.com/roniemartinez/latex2mathml/commits?author=McSinyx" title="Code">💻</a> <a href="https://github.com/roniemartinez/latex2mathml/commits?author=McSinyx" title="Tests">⚠️</a></td>
|
| 158 |
+
<td align="center" valign="top" width="14.28%"><a href="https://cdelker.github.io"><img src="https://avatars.githubusercontent.com/u/44102190?v=4?s=100" width="100px;" alt="Collin Delker"/><br /><sub><b>Collin Delker</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Acdelker" title="Bug reports">🐛</a></td>
|
| 159 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jiotv321"><img src="https://avatars.githubusercontent.com/u/118644533?v=4?s=100" width="100px;" alt="jiotv321"/><br /><sub><b>jiotv321</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/issues?q=author%3Ajiotv321" title="Bug reports">🐛</a></td>
|
| 160 |
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/felixonmars"><img src="https://avatars.githubusercontent.com/u/1006477?v=4?s=100" width="100px;" alt="Felix Yan"/><br /><sub><b>Felix Yan</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/commits?author=felixonmars" title="Code">💻</a></td>
|
| 161 |
+
<td align="center" valign="top" width="14.28%"><a href="https://rob-blackbourn.github.io/blog/"><img src="https://avatars.githubusercontent.com/u/2880305?v=4?s=100" width="100px;" alt="Rob Blackbourn"/><br /><sub><b>Rob Blackbourn</b></sub></a><br /><a href="https://github.com/roniemartinez/latex2mathml/commits?author=rob-blackbourn" title="Code">💻</a></td>
|
| 162 |
+
</tr>
|
| 163 |
+
</tbody>
|
| 164 |
+
</table>
|
| 165 |
+
|
| 166 |
+
<!-- markdownlint-restore -->
|
| 167 |
+
<!-- prettier-ignore-end -->
|
| 168 |
+
|
| 169 |
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
| 170 |
+
|
| 171 |
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
| 172 |
+
|
mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../../bin/l2m,sha256=niv3Tb2ryLVkZyAy3cO2Au_QLe-qNMmJLJm7azP4blY,237
|
| 2 |
+
../../../bin/latex2mathml,sha256=niv3Tb2ryLVkZyAy3cO2Au_QLe-qNMmJLJm7azP4blY,237
|
| 3 |
+
latex2mathml-3.77.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 4 |
+
latex2mathml-3.77.0.dist-info/LICENSE,sha256=SsHh2gf2s0PVQZHF4XFoQFNOCFkbP56uyQ1oAM3EdUM,1071
|
| 5 |
+
latex2mathml-3.77.0.dist-info/METADATA,sha256=8I_5snYGZtFTF_ZdrISzE_x4L1PcEc9WFhHJfwkOUhA,14844
|
| 6 |
+
latex2mathml-3.77.0.dist-info/RECORD,,
|
| 7 |
+
latex2mathml-3.77.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 8 |
+
latex2mathml-3.77.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
| 9 |
+
latex2mathml-3.77.0.dist-info/entry_points.txt,sha256=8cs8b08QDIhqIeEJaUBPeXlBTEE9a-d8ybiKa5ZGMak,92
|
| 10 |
+
latex2mathml/__init__.py,sha256=xA5GqWgZqbTv0TUeOiwBpOk8D48ibElsZI1OGTEnhuk,79
|
| 11 |
+
latex2mathml/__pycache__/__init__.cpython-310.pyc,,
|
| 12 |
+
latex2mathml/__pycache__/commands.cpython-310.pyc,,
|
| 13 |
+
latex2mathml/__pycache__/converter.cpython-310.pyc,,
|
| 14 |
+
latex2mathml/__pycache__/exceptions.cpython-310.pyc,,
|
| 15 |
+
latex2mathml/__pycache__/symbols_parser.cpython-310.pyc,,
|
| 16 |
+
latex2mathml/__pycache__/tokenizer.cpython-310.pyc,,
|
| 17 |
+
latex2mathml/__pycache__/walker.cpython-310.pyc,,
|
| 18 |
+
latex2mathml/commands.py,sha256=ZyBodQ-PqYfg4-LG6YipiDywzc5iUlYCLA1WTV5La04,13087
|
| 19 |
+
latex2mathml/converter.py,sha256=a3CTyam1xFz2oPkNVxklSXuPny_DmqnALLsDTRLVmeI,23219
|
| 20 |
+
latex2mathml/exceptions.py,sha256=zF1xPclVRSTzvZHPsujMv_bNITnHNW7Jvi4wg0aBQ60,645
|
| 21 |
+
latex2mathml/py.typed,sha256=JZLABTSp2pMHV6dDrYko_mqeQOmCl7_w46Ro2OaynOo,10
|
| 22 |
+
latex2mathml/symbols_parser.py,sha256=xZr_xYVWOj1-3GpdVKd0ly44AAkc2wvSmIUvbHBcJfg,2954
|
| 23 |
+
latex2mathml/tokenizer.py,sha256=FtlIzWm279chdDE6SrIohMDeHIcwT8GCeyNqexxHu94,2360
|
| 24 |
+
latex2mathml/unimathsymbols.txt,sha256=dO-JVO-vAdwfsTExPvbX97dBxPeOMPbW02ALndWlWu4,216334
|
| 25 |
+
latex2mathml/walker.py,sha256=3KZEjg4WbWQUogHmKO5yp0Ziu2n_m1JvyQs3sQc5fPA,19969
|
mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/REQUESTED
ADDED
|
File without changes
|
mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: poetry-core 1.8.1
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
mplug_owl2/lib/python3.10/site-packages/latex2mathml-3.77.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
l2m=latex2mathml.converter:main
|
| 3 |
+
latex2mathml=latex2mathml.converter:main
|
| 4 |
+
|
mplug_owl2/lib/python3.10/site-packages/linkify_it/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .main import LinkifyIt # noqa: F401p
|
| 2 |
+
from .main import SchemaError # noqa: F401p
|
| 3 |
+
|
| 4 |
+
__version__ = "2.0.3"
|
mplug_owl2/lib/python3.10/site-packages/linkify_it/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (264 Bytes). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/linkify_it/__pycache__/main.cpython-310.pyc
ADDED
|
Binary file (16.7 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/linkify_it/__pycache__/tlds.cpython-310.pyc
ADDED
|
Binary file (11.9 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/linkify_it/__pycache__/ucre.cpython-310.pyc
ADDED
|
Binary file (3.99 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/linkify_it/main.py
ADDED
|
@@ -0,0 +1,642 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
import re
|
| 3 |
+
import types
|
| 4 |
+
|
| 5 |
+
from .ucre import build_re
|
| 6 |
+
|
| 7 |
+
# py>=37: re.Pattern, else: _sre.SRE_Pattern
|
| 8 |
+
RE_TYPE = type(re.compile(r""))
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def _escape_re(string):
|
| 12 |
+
return re.sub(r"([.?*+^$[\]\\(){}|-])", r"\\\1", string)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _index_of(text, search_value):
|
| 16 |
+
try:
|
| 17 |
+
result = text.index(search_value)
|
| 18 |
+
except ValueError:
|
| 19 |
+
result = -1
|
| 20 |
+
|
| 21 |
+
return result
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class SchemaError(Exception):
|
| 25 |
+
"""Linkify schema error"""
|
| 26 |
+
|
| 27 |
+
def __init__(self, name, val):
|
| 28 |
+
message = "(LinkifyIt) Invalid schema '{}': '{}'".format(name, val)
|
| 29 |
+
super().__init__(message)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class Match:
|
| 33 |
+
"""Match result.
|
| 34 |
+
|
| 35 |
+
Attributes:
|
| 36 |
+
schema (str): Prefix (protocol) for matched string.
|
| 37 |
+
index (int): First position of matched string.
|
| 38 |
+
last_index (int): Next position after matched string.
|
| 39 |
+
raw (str): Matched string.
|
| 40 |
+
text (str): Notmalized text of matched string.
|
| 41 |
+
url (str): Normalized url of matched string.
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
linkifyit (:class:`linkify_it.main.LinkifyIt`) LinkifyIt object
|
| 45 |
+
shift (int): text searh position
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
def __repr__(self):
|
| 49 |
+
return "{}.{}({!r})".format(
|
| 50 |
+
self.__class__.__module__, self.__class__.__name__, self.__dict__
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
def __init__(self, linkifyit, shift):
|
| 54 |
+
start = linkifyit._index
|
| 55 |
+
end = linkifyit._last_index
|
| 56 |
+
text = linkifyit._text_cache[start:end]
|
| 57 |
+
|
| 58 |
+
self.schema = linkifyit._schema.lower()
|
| 59 |
+
self.index = start + shift
|
| 60 |
+
self.last_index = end + shift
|
| 61 |
+
self.raw = text
|
| 62 |
+
self.text = text
|
| 63 |
+
self.url = text
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class LinkifyIt:
|
| 67 |
+
"""Creates new linkifier instance with optional additional schemas.
|
| 68 |
+
|
| 69 |
+
By default understands:
|
| 70 |
+
|
| 71 |
+
- ``http(s)://...`` , ``ftp://...``, ``mailto:...`` & ``//...`` links
|
| 72 |
+
- "fuzzy" links and emails (example.com, foo@bar.com).
|
| 73 |
+
|
| 74 |
+
``schemas`` is an dict where each key/value describes protocol/rule:
|
| 75 |
+
|
| 76 |
+
- **key** - link prefix (usually, protocol name with ``:`` at the end, ``skype:``
|
| 77 |
+
for example). `linkify-it` makes shure that prefix is not preceeded with
|
| 78 |
+
alphanumeric char. Only whitespaces and punctuation allowed.
|
| 79 |
+
|
| 80 |
+
- **value** - rule to check tail after link prefix
|
| 81 |
+
|
| 82 |
+
- *str* - just alias to existing rule
|
| 83 |
+
- *dict*
|
| 84 |
+
|
| 85 |
+
- *validate* - either a ``re.Pattern``, ``re str`` (start with ``^``, and don't
|
| 86 |
+
include the link prefix itself), or a validator ``function`` which, given
|
| 87 |
+
arguments *self*, *text* and *pos* returns the length of a match in *text*
|
| 88 |
+
starting at index *pos*. *pos* is the index right after the link prefix.
|
| 89 |
+
- *normalize* - optional function to normalize text & url of matched
|
| 90 |
+
result (for example, for @twitter mentions).
|
| 91 |
+
|
| 92 |
+
``options`` is an dict:
|
| 93 |
+
|
| 94 |
+
- **fuzzyLink** - recognige URL-s without ``http(s):`` prefix. Default ``True``.
|
| 95 |
+
- **fuzzyIP** - allow IPs in fuzzy links above. Can conflict with some texts
|
| 96 |
+
like version numbers. Default ``False``.
|
| 97 |
+
- **fuzzyEmail** - recognize emails without ``mailto:`` prefix.
|
| 98 |
+
- **---** - set `True` to terminate link with `---` (if it's considered as long
|
| 99 |
+
dash).
|
| 100 |
+
|
| 101 |
+
Args:
|
| 102 |
+
schemas (dict): Optional. Additional schemas to validate (prefix/validator)
|
| 103 |
+
options (dict): { fuzzy_link | fuzzy_email | fuzzy_ip: True | False }.
|
| 104 |
+
Default: {"fuzzy_link": True, "fuzzy_email": True, "fuzzy_ip": False}.
|
| 105 |
+
"""
|
| 106 |
+
|
| 107 |
+
def _validate_http(self, text, pos):
|
| 108 |
+
tail = text[pos:]
|
| 109 |
+
if not self.re.get("http"):
|
| 110 |
+
# compile lazily, because "host"-containing variables can change on
|
| 111 |
+
# tlds update.
|
| 112 |
+
self.re["http"] = (
|
| 113 |
+
"^\\/\\/"
|
| 114 |
+
+ self.re["src_auth"]
|
| 115 |
+
+ self.re["src_host_port_strict"]
|
| 116 |
+
+ self.re["src_path"]
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
founds = re.search(self.re["http"], tail, flags=re.IGNORECASE)
|
| 120 |
+
if founds:
|
| 121 |
+
return len(founds.group())
|
| 122 |
+
|
| 123 |
+
return 0
|
| 124 |
+
|
| 125 |
+
def _validate_double_slash(self, text, pos):
|
| 126 |
+
tail = text[pos:]
|
| 127 |
+
|
| 128 |
+
if not self.re.get("not_http"):
|
| 129 |
+
# compile lazily, because "host"-containing variables can change on
|
| 130 |
+
# tlds update.
|
| 131 |
+
self.re["not_http"] = (
|
| 132 |
+
"^"
|
| 133 |
+
+ self.re["src_auth"]
|
| 134 |
+
+ "(?:localhost|(?:(?:"
|
| 135 |
+
+ self.re["src_domain"]
|
| 136 |
+
+ ")\\.)+"
|
| 137 |
+
+ self.re["src_domain_root"]
|
| 138 |
+
+ ")"
|
| 139 |
+
+ self.re["src_port"]
|
| 140 |
+
+ self.re["src_host_terminator"]
|
| 141 |
+
+ self.re["src_path"]
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
founds = re.search(self.re["not_http"], tail, flags=re.IGNORECASE)
|
| 145 |
+
if founds:
|
| 146 |
+
if pos >= 3 and text[pos - 3] == ":":
|
| 147 |
+
return 0
|
| 148 |
+
|
| 149 |
+
if pos >= 3 and text[pos - 3] == "/":
|
| 150 |
+
return 0
|
| 151 |
+
|
| 152 |
+
return len(founds.group(0))
|
| 153 |
+
|
| 154 |
+
return 0
|
| 155 |
+
|
| 156 |
+
def _validate_mailto(self, text, pos):
|
| 157 |
+
tail = text[pos:]
|
| 158 |
+
|
| 159 |
+
if not self.re.get("mailto"):
|
| 160 |
+
self.re["mailto"] = (
|
| 161 |
+
"^" + self.re["src_email_name"] + "@" + self.re["src_host_strict"]
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
founds = re.search(self.re["mailto"], tail, flags=re.IGNORECASE)
|
| 165 |
+
if founds:
|
| 166 |
+
return len(founds.group(0))
|
| 167 |
+
|
| 168 |
+
return 0
|
| 169 |
+
|
| 170 |
+
def _reset_scan_cache(self):
|
| 171 |
+
self._index = -1
|
| 172 |
+
self._text_cache = ""
|
| 173 |
+
|
| 174 |
+
def _create_validator(self, regex):
|
| 175 |
+
def func(text, pos):
|
| 176 |
+
tail = text[pos:]
|
| 177 |
+
if isinstance(regex, str):
|
| 178 |
+
founds = re.search(regex, tail, flags=re.IGNORECASE)
|
| 179 |
+
else:
|
| 180 |
+
# re.Pattern
|
| 181 |
+
founds = re.search(regex, tail)
|
| 182 |
+
|
| 183 |
+
if founds:
|
| 184 |
+
return len(founds.group(0))
|
| 185 |
+
|
| 186 |
+
return 0
|
| 187 |
+
|
| 188 |
+
return func
|
| 189 |
+
|
| 190 |
+
def _create_normalizer(self):
|
| 191 |
+
def func(match):
|
| 192 |
+
self.normalize(match)
|
| 193 |
+
|
| 194 |
+
return func
|
| 195 |
+
|
| 196 |
+
def _create_match(self, shift):
|
| 197 |
+
match = Match(self, shift)
|
| 198 |
+
self._compiled[match.schema]["normalize"](match)
|
| 199 |
+
return match
|
| 200 |
+
|
| 201 |
+
def __init__(self, schemas=None, options=None):
|
| 202 |
+
self.default_options = {
|
| 203 |
+
"fuzzy_link": True,
|
| 204 |
+
"fuzzy_email": True,
|
| 205 |
+
"fuzzy_ip": False,
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
self.default_schemas = {
|
| 209 |
+
"http:": {"validate": self._validate_http},
|
| 210 |
+
"https:": "http:",
|
| 211 |
+
"ftp:": "http:",
|
| 212 |
+
"//": {"validate": self._validate_double_slash},
|
| 213 |
+
"mailto:": {"validate": self._validate_mailto},
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
# RE pattern for 2-character tlds (autogenerated by ./support/tlds_2char_gen.js)
|
| 217 |
+
self.tlds_2ch_src_re = "a[cdefgilmnoqrstuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eosuw]|s[abcdeghijklmnortuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]" # noqa: E501
|
| 218 |
+
|
| 219 |
+
# DON'T try to make PRs with changes. Extend TLDs with LinkifyIt.tlds() instead
|
| 220 |
+
self.tlds_default = "biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф".split( # noqa: E501
|
| 221 |
+
"|"
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
if options:
|
| 225 |
+
self.default_options.update(options)
|
| 226 |
+
self._opts = self.default_options
|
| 227 |
+
else:
|
| 228 |
+
self._opts = self.default_options
|
| 229 |
+
|
| 230 |
+
# Cache last tested result. Used to skip repeating steps on next `match` call.
|
| 231 |
+
self._index = -1
|
| 232 |
+
self._last_index = -1 # Next scan position
|
| 233 |
+
self._schema = ""
|
| 234 |
+
self._text_cache = ""
|
| 235 |
+
|
| 236 |
+
if schemas:
|
| 237 |
+
self.default_schemas.update(schemas)
|
| 238 |
+
self._schemas = self.default_schemas
|
| 239 |
+
else:
|
| 240 |
+
self._schemas = self.default_schemas
|
| 241 |
+
|
| 242 |
+
self._compiled = {}
|
| 243 |
+
|
| 244 |
+
self._tlds = self.tlds_default
|
| 245 |
+
self._tlds_replaced = False
|
| 246 |
+
|
| 247 |
+
self.re = {}
|
| 248 |
+
|
| 249 |
+
self._compile()
|
| 250 |
+
|
| 251 |
+
def _compile(self):
|
| 252 |
+
"""Schemas compiler. Build regexps."""
|
| 253 |
+
|
| 254 |
+
# Load & clone RE patterns.
|
| 255 |
+
self.re = build_re(self._opts)
|
| 256 |
+
|
| 257 |
+
# Define dynamic patterns
|
| 258 |
+
tlds = copy.deepcopy(self._tlds)
|
| 259 |
+
|
| 260 |
+
self._on_compile()
|
| 261 |
+
|
| 262 |
+
if not self._tlds_replaced:
|
| 263 |
+
tlds.append(self.tlds_2ch_src_re)
|
| 264 |
+
tlds.append(self.re["src_xn"])
|
| 265 |
+
|
| 266 |
+
self.re["src_tlds"] = "|".join(tlds)
|
| 267 |
+
|
| 268 |
+
def untpl(tpl):
|
| 269 |
+
return tpl.replace("%TLDS%", self.re["src_tlds"])
|
| 270 |
+
|
| 271 |
+
self.re["email_fuzzy"] = untpl(self.re["tpl_email_fuzzy"])
|
| 272 |
+
|
| 273 |
+
self.re["link_fuzzy"] = untpl(self.re["tpl_link_fuzzy"])
|
| 274 |
+
|
| 275 |
+
self.re["link_no_ip_fuzzy"] = untpl(self.re["tpl_link_no_ip_fuzzy"])
|
| 276 |
+
|
| 277 |
+
self.re["host_fuzzy_test"] = untpl(self.re["tpl_host_fuzzy_test"])
|
| 278 |
+
|
| 279 |
+
#
|
| 280 |
+
# Compile each schema
|
| 281 |
+
#
|
| 282 |
+
|
| 283 |
+
aliases = []
|
| 284 |
+
|
| 285 |
+
self._compiled = {}
|
| 286 |
+
|
| 287 |
+
for name, val in self._schemas.items():
|
| 288 |
+
# skip disabled methods
|
| 289 |
+
if val is None:
|
| 290 |
+
continue
|
| 291 |
+
|
| 292 |
+
compiled = {"validate": None, "link": None}
|
| 293 |
+
|
| 294 |
+
self._compiled[name] = compiled
|
| 295 |
+
|
| 296 |
+
if isinstance(val, dict):
|
| 297 |
+
if isinstance(val.get("validate"), RE_TYPE):
|
| 298 |
+
compiled["validate"] = self._create_validator(val.get("validate"))
|
| 299 |
+
elif isinstance(val.get("validate"), str):
|
| 300 |
+
compiled["validate"] = self._create_validator(val.get("validate"))
|
| 301 |
+
elif isinstance(val.get("validate"), types.MethodType):
|
| 302 |
+
compiled["validate"] = val.get("validate")
|
| 303 |
+
# Add custom handler
|
| 304 |
+
elif isinstance(val.get("validate"), types.FunctionType):
|
| 305 |
+
setattr(LinkifyIt, "func", val.get("validate"))
|
| 306 |
+
compiled["validate"] = self.func
|
| 307 |
+
else:
|
| 308 |
+
raise SchemaError(name, val)
|
| 309 |
+
|
| 310 |
+
if isinstance(val.get("normalize"), types.MethodType):
|
| 311 |
+
compiled["normalize"] = val.get("normalize")
|
| 312 |
+
# Add custom handler
|
| 313 |
+
elif isinstance(val.get("normalize"), types.FunctionType):
|
| 314 |
+
setattr(LinkifyIt, "func", val.get("normalize"))
|
| 315 |
+
compiled["normalize"] = self.func
|
| 316 |
+
elif not val.get("normalize"):
|
| 317 |
+
compiled["normalize"] = self._create_normalizer()
|
| 318 |
+
else:
|
| 319 |
+
raise SchemaError(name, val)
|
| 320 |
+
|
| 321 |
+
continue
|
| 322 |
+
|
| 323 |
+
if isinstance(val, str):
|
| 324 |
+
aliases.append(name)
|
| 325 |
+
continue
|
| 326 |
+
|
| 327 |
+
raise SchemaError(name, val)
|
| 328 |
+
|
| 329 |
+
#
|
| 330 |
+
# Compile postponed aliases
|
| 331 |
+
#
|
| 332 |
+
for alias in aliases:
|
| 333 |
+
if not self._compiled.get(self._schemas.get(alias)):
|
| 334 |
+
continue
|
| 335 |
+
|
| 336 |
+
self._compiled[alias]["validate"] = self._compiled[self._schemas[alias]][
|
| 337 |
+
"validate"
|
| 338 |
+
]
|
| 339 |
+
self._compiled[alias]["normalize"] = self._compiled[self._schemas[alias]][
|
| 340 |
+
"normalize"
|
| 341 |
+
]
|
| 342 |
+
|
| 343 |
+
# Fake record for guessed links
|
| 344 |
+
self._compiled[""] = {"validate": None, "normalize": self._create_normalizer()}
|
| 345 |
+
|
| 346 |
+
#
|
| 347 |
+
# Build schema condition
|
| 348 |
+
#
|
| 349 |
+
slist = "|".join(
|
| 350 |
+
[
|
| 351 |
+
_escape_re(name)
|
| 352 |
+
for name, val in self._compiled.items()
|
| 353 |
+
if len(name) > 0 and val
|
| 354 |
+
]
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
re_schema_test = (
|
| 358 |
+
"(^|(?!_)(?:[><\uff5c]|" + self.re["src_ZPCc"] + "))(" + slist + ")"
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
# (?!_) cause 1.5x slowdown
|
| 362 |
+
self.re["schema_test"] = re_schema_test
|
| 363 |
+
self.re["schema_search"] = re_schema_test
|
| 364 |
+
self.re["schema_at_start"] = "^" + self.re["schema_search"]
|
| 365 |
+
|
| 366 |
+
self.re["pretest"] = (
|
| 367 |
+
"(" + re_schema_test + ")|(" + self.re["host_fuzzy_test"] + ")|@"
|
| 368 |
+
)
|
| 369 |
+
|
| 370 |
+
# Cleanup
|
| 371 |
+
|
| 372 |
+
self._reset_scan_cache()
|
| 373 |
+
|
| 374 |
+
def add(self, schema, definition):
|
| 375 |
+
"""Add new rule definition. (chainable)
|
| 376 |
+
|
| 377 |
+
See :class:`linkify_it.main.LinkifyIt` init description for details.
|
| 378 |
+
``schema`` is a link prefix (``skype:``, for example), and ``definition``
|
| 379 |
+
is a ``str`` to alias to another schema, or an ``dict`` with ``validate`` and
|
| 380 |
+
optionally `normalize` definitions. To disable an existing rule, use
|
| 381 |
+
``.add(<schema>, None)``.
|
| 382 |
+
|
| 383 |
+
Args:
|
| 384 |
+
schema (str): rule name (fixed pattern prefix)
|
| 385 |
+
definition (`str` or `re.Pattern`): schema definition
|
| 386 |
+
|
| 387 |
+
Return:
|
| 388 |
+
:class:`linkify_it.main.LinkifyIt`
|
| 389 |
+
"""
|
| 390 |
+
self._schemas[schema] = definition
|
| 391 |
+
self._compile()
|
| 392 |
+
return self
|
| 393 |
+
|
| 394 |
+
def set(self, options):
|
| 395 |
+
"""Override default options. (chainable)
|
| 396 |
+
|
| 397 |
+
Missed properties will not be changed.
|
| 398 |
+
|
| 399 |
+
Args:
|
| 400 |
+
options (dict): ``keys``: [``fuzzy_link`` | ``fuzzy_email`` | ``fuzzy_ip``].
|
| 401 |
+
``values``: [``True`` | ``False``]
|
| 402 |
+
|
| 403 |
+
Return:
|
| 404 |
+
:class:`linkify_it.main.LinkifyIt`
|
| 405 |
+
"""
|
| 406 |
+
self._opts.update(options)
|
| 407 |
+
return self
|
| 408 |
+
|
| 409 |
+
def test(self, text):
|
| 410 |
+
"""Searches linkifiable pattern and returns ``True`` on success or ``False``
|
| 411 |
+
on fail.
|
| 412 |
+
|
| 413 |
+
Args:
|
| 414 |
+
text (str): text to search
|
| 415 |
+
|
| 416 |
+
Returns:
|
| 417 |
+
bool: ``True`` if a linkable pattern was found, otherwise it is ``False``.
|
| 418 |
+
"""
|
| 419 |
+
self._text_cache = text
|
| 420 |
+
self._index = -1
|
| 421 |
+
|
| 422 |
+
if not len(text):
|
| 423 |
+
return False
|
| 424 |
+
|
| 425 |
+
if re.search(self.re["schema_test"], text, flags=re.IGNORECASE):
|
| 426 |
+
regex = self.re["schema_search"]
|
| 427 |
+
last_index = 0
|
| 428 |
+
matched_iter = re.finditer(regex, text[last_index:], flags=re.IGNORECASE)
|
| 429 |
+
for matched in matched_iter:
|
| 430 |
+
last_index = matched.end(0)
|
| 431 |
+
m = (matched.group(), matched.groups()[0], matched.groups()[1])
|
| 432 |
+
length = self.test_schema_at(text, m[2], last_index)
|
| 433 |
+
if length:
|
| 434 |
+
self._schema = m[2]
|
| 435 |
+
self._index = matched.start(0) + len(m[1])
|
| 436 |
+
self._last_index = matched.start(0) + len(m[0]) + length
|
| 437 |
+
break
|
| 438 |
+
|
| 439 |
+
if self._opts.get("fuzzy_link") and self._compiled.get("http:"):
|
| 440 |
+
# guess schemaless links
|
| 441 |
+
matched_tld = re.search(
|
| 442 |
+
self.re["host_fuzzy_test"], text, flags=re.IGNORECASE
|
| 443 |
+
)
|
| 444 |
+
if matched_tld:
|
| 445 |
+
tld_pos = matched_tld.start(0)
|
| 446 |
+
else:
|
| 447 |
+
tld_pos = -1
|
| 448 |
+
if tld_pos >= 0:
|
| 449 |
+
# if tld is located after found link - no need to check fuzzy pattern
|
| 450 |
+
if self._index < 0 or tld_pos < self._index:
|
| 451 |
+
if self._opts.get("fuzzy_ip"):
|
| 452 |
+
pattern = self.re["link_fuzzy"]
|
| 453 |
+
else:
|
| 454 |
+
pattern = self.re["link_no_ip_fuzzy"]
|
| 455 |
+
|
| 456 |
+
ml = re.search(pattern, text, flags=re.IGNORECASE)
|
| 457 |
+
if ml:
|
| 458 |
+
shift = ml.start(0) + len(ml.groups()[0])
|
| 459 |
+
|
| 460 |
+
if self._index < 0 or shift < self._index:
|
| 461 |
+
self._schema = ""
|
| 462 |
+
self._index = shift
|
| 463 |
+
self._last_index = ml.start(0) + len(ml.group())
|
| 464 |
+
|
| 465 |
+
if self._opts.get("fuzzy_email") and self._compiled.get("mailto:"):
|
| 466 |
+
# guess schemaless emails
|
| 467 |
+
at_pos = _index_of(text, "@")
|
| 468 |
+
if at_pos >= 0:
|
| 469 |
+
# We can't skip this check, because this cases are possible:
|
| 470 |
+
# 192.168.1.1@gmail.com, my.in@example.com
|
| 471 |
+
me = re.search(self.re["email_fuzzy"], text, flags=re.IGNORECASE)
|
| 472 |
+
if me:
|
| 473 |
+
shift = me.start(0) + len(me.groups()[0])
|
| 474 |
+
next_shift = me.start(0) + len(me.group())
|
| 475 |
+
|
| 476 |
+
if (
|
| 477 |
+
self._index < 0
|
| 478 |
+
or shift < self._index
|
| 479 |
+
or (shift == self._index and next_shift > self._last_index)
|
| 480 |
+
):
|
| 481 |
+
self._schema = "mailto:"
|
| 482 |
+
self._index = shift
|
| 483 |
+
self._last_index = next_shift
|
| 484 |
+
|
| 485 |
+
return self._index >= 0
|
| 486 |
+
|
| 487 |
+
def pretest(self, text):
|
| 488 |
+
"""Very quick check, that can give false positives.
|
| 489 |
+
|
| 490 |
+
Returns true if link MAY BE can exists. Can be used for speed optimization,
|
| 491 |
+
when you need to check that link NOT exists.
|
| 492 |
+
|
| 493 |
+
Args:
|
| 494 |
+
text (str): text to search
|
| 495 |
+
|
| 496 |
+
Returns:
|
| 497 |
+
bool: ``True`` if a linkable pattern was found, otherwise it is ``False``.
|
| 498 |
+
"""
|
| 499 |
+
if re.search(self.re["pretest"], text, flags=re.IGNORECASE):
|
| 500 |
+
return True
|
| 501 |
+
|
| 502 |
+
return False
|
| 503 |
+
|
| 504 |
+
def test_schema_at(self, text, name, position):
|
| 505 |
+
"""Similar to :meth:`linkify_it.main.LinkifyIt.test` but checks only
|
| 506 |
+
specific protocol tail exactly at given position.
|
| 507 |
+
|
| 508 |
+
Args:
|
| 509 |
+
text (str): text to scan
|
| 510 |
+
name (str): rule (schema) name
|
| 511 |
+
position (int): length of found pattern (0 on fail).
|
| 512 |
+
|
| 513 |
+
Returns:
|
| 514 |
+
int: text (str): text to search
|
| 515 |
+
"""
|
| 516 |
+
# If not supported schema check requested - terminate
|
| 517 |
+
if not self._compiled.get(name.lower()):
|
| 518 |
+
return 0
|
| 519 |
+
return self._compiled.get(name.lower()).get("validate")(text, position)
|
| 520 |
+
|
| 521 |
+
def match(self, text):
|
| 522 |
+
"""Returns ``list`` of found link descriptions or ``None`` on fail.
|
| 523 |
+
|
| 524 |
+
We strongly recommend to use :meth:`linkify_it.main.LinkifyIt.test`
|
| 525 |
+
first, for best speed.
|
| 526 |
+
|
| 527 |
+
Args:
|
| 528 |
+
text (str): text to search
|
| 529 |
+
|
| 530 |
+
Returns:
|
| 531 |
+
``list`` or ``None``: Result match description:
|
| 532 |
+
* **schema** - link schema, can be empty for fuzzy links, or ``//``
|
| 533 |
+
for protocol-neutral links.
|
| 534 |
+
* **index** - offset of matched text
|
| 535 |
+
* **last_index** - offset of matched text
|
| 536 |
+
* **raw** - offset of matched text
|
| 537 |
+
* **text** - normalized text
|
| 538 |
+
* **url** - link, generated from matched text
|
| 539 |
+
"""
|
| 540 |
+
shift = 0
|
| 541 |
+
result = []
|
| 542 |
+
|
| 543 |
+
# try to take previous element from cache, if .test() called before
|
| 544 |
+
if self._index >= 0 and self._text_cache == text:
|
| 545 |
+
result.append(self._create_match(shift))
|
| 546 |
+
shift = self._last_index
|
| 547 |
+
|
| 548 |
+
# Cut head if cache was used
|
| 549 |
+
tail = text[shift:] if shift else text
|
| 550 |
+
|
| 551 |
+
# Scan string until end reached
|
| 552 |
+
while self.test(tail):
|
| 553 |
+
result.append(self._create_match(shift))
|
| 554 |
+
|
| 555 |
+
tail = tail[self._last_index :]
|
| 556 |
+
shift += self._last_index
|
| 557 |
+
|
| 558 |
+
if len(result):
|
| 559 |
+
return result
|
| 560 |
+
|
| 561 |
+
return None
|
| 562 |
+
|
| 563 |
+
def match_at_start(self, text):
|
| 564 |
+
"""Returns fully-formed (not fuzzy) link if it starts at the beginning
|
| 565 |
+
of the string, and null otherwise.
|
| 566 |
+
|
| 567 |
+
Args:
|
| 568 |
+
text (str): text to search
|
| 569 |
+
|
| 570 |
+
Retuns:
|
| 571 |
+
``Match`` or ``None``
|
| 572 |
+
"""
|
| 573 |
+
# Reset scan cache
|
| 574 |
+
self._text_cache = text
|
| 575 |
+
self._index = -1
|
| 576 |
+
|
| 577 |
+
if not len(text):
|
| 578 |
+
return None
|
| 579 |
+
|
| 580 |
+
founds = re.search(self.re["schema_at_start"], text, flags=re.IGNORECASE)
|
| 581 |
+
if not founds:
|
| 582 |
+
return None
|
| 583 |
+
|
| 584 |
+
m = (founds.group(), founds.groups()[0], founds.groups()[1])
|
| 585 |
+
length = self.test_schema_at(text, m[2], len(m[0]))
|
| 586 |
+
if not length:
|
| 587 |
+
return None
|
| 588 |
+
|
| 589 |
+
self._schema = m[2]
|
| 590 |
+
self._index = founds.start(0) + len(m[1])
|
| 591 |
+
self._last_index = founds.start(0) + len(m[0]) + length
|
| 592 |
+
|
| 593 |
+
return self._create_match(0)
|
| 594 |
+
|
| 595 |
+
def tlds(self, list_tlds, keep_old=False):
|
| 596 |
+
"""Load (or merge) new tlds list. (chainable)
|
| 597 |
+
|
| 598 |
+
Those are user for fuzzy links (without prefix) to avoid false positives.
|
| 599 |
+
By default this algorythm used:
|
| 600 |
+
|
| 601 |
+
* hostname with any 2-letter root zones are ok.
|
| 602 |
+
* biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф
|
| 603 |
+
are ok.
|
| 604 |
+
* encoded (`xn--...`) root zones are ok.
|
| 605 |
+
|
| 606 |
+
If list is replaced, then exact match for 2-chars root zones will be checked.
|
| 607 |
+
|
| 608 |
+
Args:
|
| 609 |
+
list_tlds (list or str): ``list of tlds`` or ``tlds string``
|
| 610 |
+
keep_old (bool): merge with current list if q`True`q (q`Falseq` by default)
|
| 611 |
+
"""
|
| 612 |
+
_list = list_tlds if isinstance(list_tlds, list) else [list_tlds]
|
| 613 |
+
|
| 614 |
+
if not keep_old:
|
| 615 |
+
self._tlds = _list
|
| 616 |
+
self._tlds_replaced = True
|
| 617 |
+
self._compile()
|
| 618 |
+
return self
|
| 619 |
+
|
| 620 |
+
self._tlds.extend(_list)
|
| 621 |
+
self._tlds = sorted(list(set(self._tlds)), reverse=True)
|
| 622 |
+
|
| 623 |
+
self._compile()
|
| 624 |
+
return self
|
| 625 |
+
|
| 626 |
+
def normalize(self, match):
|
| 627 |
+
"""Default normalizer (if schema does not define it's own).
|
| 628 |
+
|
| 629 |
+
Args:
|
| 630 |
+
match (:class:`linkify_it.main.Match`): Match result
|
| 631 |
+
"""
|
| 632 |
+
if not match.schema:
|
| 633 |
+
match.url = "http://" + match.url
|
| 634 |
+
|
| 635 |
+
if match.schema == "mailto:" and not re.search(
|
| 636 |
+
"^mailto:", match.url, flags=re.IGNORECASE
|
| 637 |
+
):
|
| 638 |
+
match.url = "mailto:" + match.url
|
| 639 |
+
|
| 640 |
+
def _on_compile(self):
|
| 641 |
+
"""Override to modify basic RegExp-s."""
|
| 642 |
+
pass
|
mplug_owl2/lib/python3.10/site-packages/linkify_it/tlds.py
ADDED
|
@@ -0,0 +1,1517 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""TLDS
|
| 2 |
+
|
| 3 |
+
Version 2020110600, Last Updated Fri Nov 6 07:07:02 2020 UTC
|
| 4 |
+
|
| 5 |
+
References:
|
| 6 |
+
http://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
| 7 |
+
"""
|
| 8 |
+
TLDS = [
|
| 9 |
+
"AAA",
|
| 10 |
+
"AARP",
|
| 11 |
+
"ABARTH",
|
| 12 |
+
"ABB",
|
| 13 |
+
"ABBOTT",
|
| 14 |
+
"ABBVIE",
|
| 15 |
+
"ABC",
|
| 16 |
+
"ABLE",
|
| 17 |
+
"ABOGADO",
|
| 18 |
+
"ABUDHABI",
|
| 19 |
+
"AC",
|
| 20 |
+
"ACADEMY",
|
| 21 |
+
"ACCENTURE",
|
| 22 |
+
"ACCOUNTANT",
|
| 23 |
+
"ACCOUNTANTS",
|
| 24 |
+
"ACO",
|
| 25 |
+
"ACTOR",
|
| 26 |
+
"AD",
|
| 27 |
+
"ADAC",
|
| 28 |
+
"ADS",
|
| 29 |
+
"ADULT",
|
| 30 |
+
"AE",
|
| 31 |
+
"AEG",
|
| 32 |
+
"AERO",
|
| 33 |
+
"AETNA",
|
| 34 |
+
"AF",
|
| 35 |
+
"AFAMILYCOMPANY",
|
| 36 |
+
"AFL",
|
| 37 |
+
"AFRICA",
|
| 38 |
+
"AG",
|
| 39 |
+
"AGAKHAN",
|
| 40 |
+
"AGENCY",
|
| 41 |
+
"AI",
|
| 42 |
+
"AIG",
|
| 43 |
+
"AIRBUS",
|
| 44 |
+
"AIRFORCE",
|
| 45 |
+
"AIRTEL",
|
| 46 |
+
"AKDN",
|
| 47 |
+
"AL",
|
| 48 |
+
"ALFAROMEO",
|
| 49 |
+
"ALIBABA",
|
| 50 |
+
"ALIPAY",
|
| 51 |
+
"ALLFINANZ",
|
| 52 |
+
"ALLSTATE",
|
| 53 |
+
"ALLY",
|
| 54 |
+
"ALSACE",
|
| 55 |
+
"ALSTOM",
|
| 56 |
+
"AM",
|
| 57 |
+
"AMAZON",
|
| 58 |
+
"AMERICANEXPRESS",
|
| 59 |
+
"AMERICANFAMILY",
|
| 60 |
+
"AMEX",
|
| 61 |
+
"AMFAM",
|
| 62 |
+
"AMICA",
|
| 63 |
+
"AMSTERDAM",
|
| 64 |
+
"ANALYTICS",
|
| 65 |
+
"ANDROID",
|
| 66 |
+
"ANQUAN",
|
| 67 |
+
"ANZ",
|
| 68 |
+
"AO",
|
| 69 |
+
"AOL",
|
| 70 |
+
"APARTMENTS",
|
| 71 |
+
"APP",
|
| 72 |
+
"APPLE",
|
| 73 |
+
"AQ",
|
| 74 |
+
"AQUARELLE",
|
| 75 |
+
"AR",
|
| 76 |
+
"ARAB",
|
| 77 |
+
"ARAMCO",
|
| 78 |
+
"ARCHI",
|
| 79 |
+
"ARMY",
|
| 80 |
+
"ARPA",
|
| 81 |
+
"ART",
|
| 82 |
+
"ARTE",
|
| 83 |
+
"AS",
|
| 84 |
+
"ASDA",
|
| 85 |
+
"ASIA",
|
| 86 |
+
"ASSOCIATES",
|
| 87 |
+
"AT",
|
| 88 |
+
"ATHLETA",
|
| 89 |
+
"ATTORNEY",
|
| 90 |
+
"AU",
|
| 91 |
+
"AUCTION",
|
| 92 |
+
"AUDI",
|
| 93 |
+
"AUDIBLE",
|
| 94 |
+
"AUDIO",
|
| 95 |
+
"AUSPOST",
|
| 96 |
+
"AUTHOR",
|
| 97 |
+
"AUTO",
|
| 98 |
+
"AUTOS",
|
| 99 |
+
"AVIANCA",
|
| 100 |
+
"AW",
|
| 101 |
+
"AWS",
|
| 102 |
+
"AX",
|
| 103 |
+
"AXA",
|
| 104 |
+
"AZ",
|
| 105 |
+
"AZURE",
|
| 106 |
+
"BA",
|
| 107 |
+
"BABY",
|
| 108 |
+
"BAIDU",
|
| 109 |
+
"BANAMEX",
|
| 110 |
+
"BANANAREPUBLIC",
|
| 111 |
+
"BAND",
|
| 112 |
+
"BANK",
|
| 113 |
+
"BAR",
|
| 114 |
+
"BARCELONA",
|
| 115 |
+
"BARCLAYCARD",
|
| 116 |
+
"BARCLAYS",
|
| 117 |
+
"BAREFOOT",
|
| 118 |
+
"BARGAINS",
|
| 119 |
+
"BASEBALL",
|
| 120 |
+
"BASKETBALL",
|
| 121 |
+
"BAUHAUS",
|
| 122 |
+
"BAYERN",
|
| 123 |
+
"BB",
|
| 124 |
+
"BBC",
|
| 125 |
+
"BBT",
|
| 126 |
+
"BBVA",
|
| 127 |
+
"BCG",
|
| 128 |
+
"BCN",
|
| 129 |
+
"BD",
|
| 130 |
+
"BE",
|
| 131 |
+
"BEATS",
|
| 132 |
+
"BEAUTY",
|
| 133 |
+
"BEER",
|
| 134 |
+
"BENTLEY",
|
| 135 |
+
"BERLIN",
|
| 136 |
+
"BEST",
|
| 137 |
+
"BESTBUY",
|
| 138 |
+
"BET",
|
| 139 |
+
"BF",
|
| 140 |
+
"BG",
|
| 141 |
+
"BH",
|
| 142 |
+
"BHARTI",
|
| 143 |
+
"BI",
|
| 144 |
+
"BIBLE",
|
| 145 |
+
"BID",
|
| 146 |
+
"BIKE",
|
| 147 |
+
"BING",
|
| 148 |
+
"BINGO",
|
| 149 |
+
"BIO",
|
| 150 |
+
"BIZ",
|
| 151 |
+
"BJ",
|
| 152 |
+
"BLACK",
|
| 153 |
+
"BLACKFRIDAY",
|
| 154 |
+
"BLOCKBUSTER",
|
| 155 |
+
"BLOG",
|
| 156 |
+
"BLOOMBERG",
|
| 157 |
+
"BLUE",
|
| 158 |
+
"BM",
|
| 159 |
+
"BMS",
|
| 160 |
+
"BMW",
|
| 161 |
+
"BN",
|
| 162 |
+
"BNPPARIBAS",
|
| 163 |
+
"BO",
|
| 164 |
+
"BOATS",
|
| 165 |
+
"BOEHRINGER",
|
| 166 |
+
"BOFA",
|
| 167 |
+
"BOM",
|
| 168 |
+
"BOND",
|
| 169 |
+
"BOO",
|
| 170 |
+
"BOOK",
|
| 171 |
+
"BOOKING",
|
| 172 |
+
"BOSCH",
|
| 173 |
+
"BOSTIK",
|
| 174 |
+
"BOSTON",
|
| 175 |
+
"BOT",
|
| 176 |
+
"BOUTIQUE",
|
| 177 |
+
"BOX",
|
| 178 |
+
"BR",
|
| 179 |
+
"BRADESCO",
|
| 180 |
+
"BRIDGESTONE",
|
| 181 |
+
"BROADWAY",
|
| 182 |
+
"BROKER",
|
| 183 |
+
"BROTHER",
|
| 184 |
+
"BRUSSELS",
|
| 185 |
+
"BS",
|
| 186 |
+
"BT",
|
| 187 |
+
"BUDAPEST",
|
| 188 |
+
"BUGATTI",
|
| 189 |
+
"BUILD",
|
| 190 |
+
"BUILDERS",
|
| 191 |
+
"BUSINESS",
|
| 192 |
+
"BUY",
|
| 193 |
+
"BUZZ",
|
| 194 |
+
"BV",
|
| 195 |
+
"BW",
|
| 196 |
+
"BY",
|
| 197 |
+
"BZ",
|
| 198 |
+
"BZH",
|
| 199 |
+
"CA",
|
| 200 |
+
"CAB",
|
| 201 |
+
"CAFE",
|
| 202 |
+
"CAL",
|
| 203 |
+
"CALL",
|
| 204 |
+
"CALVINKLEIN",
|
| 205 |
+
"CAM",
|
| 206 |
+
"CAMERA",
|
| 207 |
+
"CAMP",
|
| 208 |
+
"CANCERRESEARCH",
|
| 209 |
+
"CANON",
|
| 210 |
+
"CAPETOWN",
|
| 211 |
+
"CAPITAL",
|
| 212 |
+
"CAPITALONE",
|
| 213 |
+
"CAR",
|
| 214 |
+
"CARAVAN",
|
| 215 |
+
"CARDS",
|
| 216 |
+
"CARE",
|
| 217 |
+
"CAREER",
|
| 218 |
+
"CAREERS",
|
| 219 |
+
"CARS",
|
| 220 |
+
"CASA",
|
| 221 |
+
"CASE",
|
| 222 |
+
"CASEIH",
|
| 223 |
+
"CASH",
|
| 224 |
+
"CASINO",
|
| 225 |
+
"CAT",
|
| 226 |
+
"CATERING",
|
| 227 |
+
"CATHOLIC",
|
| 228 |
+
"CBA",
|
| 229 |
+
"CBN",
|
| 230 |
+
"CBRE",
|
| 231 |
+
"CBS",
|
| 232 |
+
"CC",
|
| 233 |
+
"CD",
|
| 234 |
+
"CEB",
|
| 235 |
+
"CENTER",
|
| 236 |
+
"CEO",
|
| 237 |
+
"CERN",
|
| 238 |
+
"CF",
|
| 239 |
+
"CFA",
|
| 240 |
+
"CFD",
|
| 241 |
+
"CG",
|
| 242 |
+
"CH",
|
| 243 |
+
"CHANEL",
|
| 244 |
+
"CHANNEL",
|
| 245 |
+
"CHARITY",
|
| 246 |
+
"CHASE",
|
| 247 |
+
"CHAT",
|
| 248 |
+
"CHEAP",
|
| 249 |
+
"CHINTAI",
|
| 250 |
+
"CHRISTMAS",
|
| 251 |
+
"CHROME",
|
| 252 |
+
"CHURCH",
|
| 253 |
+
"CI",
|
| 254 |
+
"CIPRIANI",
|
| 255 |
+
"CIRCLE",
|
| 256 |
+
"CISCO",
|
| 257 |
+
"CITADEL",
|
| 258 |
+
"CITI",
|
| 259 |
+
"CITIC",
|
| 260 |
+
"CITY",
|
| 261 |
+
"CITYEATS",
|
| 262 |
+
"CK",
|
| 263 |
+
"CL",
|
| 264 |
+
"CLAIMS",
|
| 265 |
+
"CLEANING",
|
| 266 |
+
"CLICK",
|
| 267 |
+
"CLINIC",
|
| 268 |
+
"CLINIQUE",
|
| 269 |
+
"CLOTHING",
|
| 270 |
+
"CLOUD",
|
| 271 |
+
"CLUB",
|
| 272 |
+
"CLUBMED",
|
| 273 |
+
"CM",
|
| 274 |
+
"CN",
|
| 275 |
+
"CO",
|
| 276 |
+
"COACH",
|
| 277 |
+
"CODES",
|
| 278 |
+
"COFFEE",
|
| 279 |
+
"COLLEGE",
|
| 280 |
+
"COLOGNE",
|
| 281 |
+
"COM",
|
| 282 |
+
"COMCAST",
|
| 283 |
+
"COMMBANK",
|
| 284 |
+
"COMMUNITY",
|
| 285 |
+
"COMPANY",
|
| 286 |
+
"COMPARE",
|
| 287 |
+
"COMPUTER",
|
| 288 |
+
"COMSEC",
|
| 289 |
+
"CONDOS",
|
| 290 |
+
"CONSTRUCTION",
|
| 291 |
+
"CONSULTING",
|
| 292 |
+
"CONTACT",
|
| 293 |
+
"CONTRACTORS",
|
| 294 |
+
"COOKING",
|
| 295 |
+
"COOKINGCHANNEL",
|
| 296 |
+
"COOL",
|
| 297 |
+
"COOP",
|
| 298 |
+
"CORSICA",
|
| 299 |
+
"COUNTRY",
|
| 300 |
+
"COUPON",
|
| 301 |
+
"COUPONS",
|
| 302 |
+
"COURSES",
|
| 303 |
+
"CPA",
|
| 304 |
+
"CR",
|
| 305 |
+
"CREDIT",
|
| 306 |
+
"CREDITCARD",
|
| 307 |
+
"CREDITUNION",
|
| 308 |
+
"CRICKET",
|
| 309 |
+
"CROWN",
|
| 310 |
+
"CRS",
|
| 311 |
+
"CRUISE",
|
| 312 |
+
"CRUISES",
|
| 313 |
+
"CSC",
|
| 314 |
+
"CU",
|
| 315 |
+
"CUISINELLA",
|
| 316 |
+
"CV",
|
| 317 |
+
"CW",
|
| 318 |
+
"CX",
|
| 319 |
+
"CY",
|
| 320 |
+
"CYMRU",
|
| 321 |
+
"CYOU",
|
| 322 |
+
"CZ",
|
| 323 |
+
"DABUR",
|
| 324 |
+
"DAD",
|
| 325 |
+
"DANCE",
|
| 326 |
+
"DATA",
|
| 327 |
+
"DATE",
|
| 328 |
+
"DATING",
|
| 329 |
+
"DATSUN",
|
| 330 |
+
"DAY",
|
| 331 |
+
"DCLK",
|
| 332 |
+
"DDS",
|
| 333 |
+
"DE",
|
| 334 |
+
"DEAL",
|
| 335 |
+
"DEALER",
|
| 336 |
+
"DEALS",
|
| 337 |
+
"DEGREE",
|
| 338 |
+
"DELIVERY",
|
| 339 |
+
"DELL",
|
| 340 |
+
"DELOITTE",
|
| 341 |
+
"DELTA",
|
| 342 |
+
"DEMOCRAT",
|
| 343 |
+
"DENTAL",
|
| 344 |
+
"DENTIST",
|
| 345 |
+
"DESI",
|
| 346 |
+
"DESIGN",
|
| 347 |
+
"DEV",
|
| 348 |
+
"DHL",
|
| 349 |
+
"DIAMONDS",
|
| 350 |
+
"DIET",
|
| 351 |
+
"DIGITAL",
|
| 352 |
+
"DIRECT",
|
| 353 |
+
"DIRECTORY",
|
| 354 |
+
"DISCOUNT",
|
| 355 |
+
"DISCOVER",
|
| 356 |
+
"DISH",
|
| 357 |
+
"DIY",
|
| 358 |
+
"DJ",
|
| 359 |
+
"DK",
|
| 360 |
+
"DM",
|
| 361 |
+
"DNP",
|
| 362 |
+
"DO",
|
| 363 |
+
"DOCS",
|
| 364 |
+
"DOCTOR",
|
| 365 |
+
"DOG",
|
| 366 |
+
"DOMAINS",
|
| 367 |
+
"DOT",
|
| 368 |
+
"DOWNLOAD",
|
| 369 |
+
"DRIVE",
|
| 370 |
+
"DTV",
|
| 371 |
+
"DUBAI",
|
| 372 |
+
"DUCK",
|
| 373 |
+
"DUNLOP",
|
| 374 |
+
"DUPONT",
|
| 375 |
+
"DURBAN",
|
| 376 |
+
"DVAG",
|
| 377 |
+
"DVR",
|
| 378 |
+
"DZ",
|
| 379 |
+
"EARTH",
|
| 380 |
+
"EAT",
|
| 381 |
+
"EC",
|
| 382 |
+
"ECO",
|
| 383 |
+
"EDEKA",
|
| 384 |
+
"EDU",
|
| 385 |
+
"EDUCATION",
|
| 386 |
+
"EE",
|
| 387 |
+
"EG",
|
| 388 |
+
"EMAIL",
|
| 389 |
+
"EMERCK",
|
| 390 |
+
"ENERGY",
|
| 391 |
+
"ENGINEER",
|
| 392 |
+
"ENGINEERING",
|
| 393 |
+
"ENTERPRISES",
|
| 394 |
+
"EPSON",
|
| 395 |
+
"EQUIPMENT",
|
| 396 |
+
"ER",
|
| 397 |
+
"ERICSSON",
|
| 398 |
+
"ERNI",
|
| 399 |
+
"ES",
|
| 400 |
+
"ESQ",
|
| 401 |
+
"ESTATE",
|
| 402 |
+
"ET",
|
| 403 |
+
"ETISALAT",
|
| 404 |
+
"EU",
|
| 405 |
+
"EUROVISION",
|
| 406 |
+
"EUS",
|
| 407 |
+
"EVENTS",
|
| 408 |
+
"EXCHANGE",
|
| 409 |
+
"EXPERT",
|
| 410 |
+
"EXPOSED",
|
| 411 |
+
"EXPRESS",
|
| 412 |
+
"EXTRASPACE",
|
| 413 |
+
"FAGE",
|
| 414 |
+
"FAIL",
|
| 415 |
+
"FAIRWINDS",
|
| 416 |
+
"FAITH",
|
| 417 |
+
"FAMILY",
|
| 418 |
+
"FAN",
|
| 419 |
+
"FANS",
|
| 420 |
+
"FARM",
|
| 421 |
+
"FARMERS",
|
| 422 |
+
"FASHION",
|
| 423 |
+
"FAST",
|
| 424 |
+
"FEDEX",
|
| 425 |
+
"FEEDBACK",
|
| 426 |
+
"FERRARI",
|
| 427 |
+
"FERRERO",
|
| 428 |
+
"FI",
|
| 429 |
+
"FIAT",
|
| 430 |
+
"FIDELITY",
|
| 431 |
+
"FIDO",
|
| 432 |
+
"FILM",
|
| 433 |
+
"FINAL",
|
| 434 |
+
"FINANCE",
|
| 435 |
+
"FINANCIAL",
|
| 436 |
+
"FIRE",
|
| 437 |
+
"FIRESTONE",
|
| 438 |
+
"FIRMDALE",
|
| 439 |
+
"FISH",
|
| 440 |
+
"FISHING",
|
| 441 |
+
"FIT",
|
| 442 |
+
"FITNESS",
|
| 443 |
+
"FJ",
|
| 444 |
+
"FK",
|
| 445 |
+
"FLICKR",
|
| 446 |
+
"FLIGHTS",
|
| 447 |
+
"FLIR",
|
| 448 |
+
"FLORIST",
|
| 449 |
+
"FLOWERS",
|
| 450 |
+
"FLY",
|
| 451 |
+
"FM",
|
| 452 |
+
"FO",
|
| 453 |
+
"FOO",
|
| 454 |
+
"FOOD",
|
| 455 |
+
"FOODNETWORK",
|
| 456 |
+
"FOOTBALL",
|
| 457 |
+
"FORD",
|
| 458 |
+
"FOREX",
|
| 459 |
+
"FORSALE",
|
| 460 |
+
"FORUM",
|
| 461 |
+
"FOUNDATION",
|
| 462 |
+
"FOX",
|
| 463 |
+
"FR",
|
| 464 |
+
"FREE",
|
| 465 |
+
"FRESENIUS",
|
| 466 |
+
"FRL",
|
| 467 |
+
"FROGANS",
|
| 468 |
+
"FRONTDOOR",
|
| 469 |
+
"FRONTIER",
|
| 470 |
+
"FTR",
|
| 471 |
+
"FUJITSU",
|
| 472 |
+
"FUJIXEROX",
|
| 473 |
+
"FUN",
|
| 474 |
+
"FUND",
|
| 475 |
+
"FURNITURE",
|
| 476 |
+
"FUTBOL",
|
| 477 |
+
"FYI",
|
| 478 |
+
"GA",
|
| 479 |
+
"GAL",
|
| 480 |
+
"GALLERY",
|
| 481 |
+
"GALLO",
|
| 482 |
+
"GALLUP",
|
| 483 |
+
"GAME",
|
| 484 |
+
"GAMES",
|
| 485 |
+
"GAP",
|
| 486 |
+
"GARDEN",
|
| 487 |
+
"GAY",
|
| 488 |
+
"GB",
|
| 489 |
+
"GBIZ",
|
| 490 |
+
"GD",
|
| 491 |
+
"GDN",
|
| 492 |
+
"GE",
|
| 493 |
+
"GEA",
|
| 494 |
+
"GENT",
|
| 495 |
+
"GENTING",
|
| 496 |
+
"GEORGE",
|
| 497 |
+
"GF",
|
| 498 |
+
"GG",
|
| 499 |
+
"GGEE",
|
| 500 |
+
"GH",
|
| 501 |
+
"GI",
|
| 502 |
+
"GIFT",
|
| 503 |
+
"GIFTS",
|
| 504 |
+
"GIVES",
|
| 505 |
+
"GIVING",
|
| 506 |
+
"GL",
|
| 507 |
+
"GLADE",
|
| 508 |
+
"GLASS",
|
| 509 |
+
"GLE",
|
| 510 |
+
"GLOBAL",
|
| 511 |
+
"GLOBO",
|
| 512 |
+
"GM",
|
| 513 |
+
"GMAIL",
|
| 514 |
+
"GMBH",
|
| 515 |
+
"GMO",
|
| 516 |
+
"GMX",
|
| 517 |
+
"GN",
|
| 518 |
+
"GODADDY",
|
| 519 |
+
"GOLD",
|
| 520 |
+
"GOLDPOINT",
|
| 521 |
+
"GOLF",
|
| 522 |
+
"GOO",
|
| 523 |
+
"GOODYEAR",
|
| 524 |
+
"GOOG",
|
| 525 |
+
"GOOGLE",
|
| 526 |
+
"GOP",
|
| 527 |
+
"GOT",
|
| 528 |
+
"GOV",
|
| 529 |
+
"GP",
|
| 530 |
+
"GQ",
|
| 531 |
+
"GR",
|
| 532 |
+
"GRAINGER",
|
| 533 |
+
"GRAPHICS",
|
| 534 |
+
"GRATIS",
|
| 535 |
+
"GREEN",
|
| 536 |
+
"GRIPE",
|
| 537 |
+
"GROCERY",
|
| 538 |
+
"GROUP",
|
| 539 |
+
"GS",
|
| 540 |
+
"GT",
|
| 541 |
+
"GU",
|
| 542 |
+
"GUARDIAN",
|
| 543 |
+
"GUCCI",
|
| 544 |
+
"GUGE",
|
| 545 |
+
"GUIDE",
|
| 546 |
+
"GUITARS",
|
| 547 |
+
"GURU",
|
| 548 |
+
"GW",
|
| 549 |
+
"GY",
|
| 550 |
+
"HAIR",
|
| 551 |
+
"HAMBURG",
|
| 552 |
+
"HANGOUT",
|
| 553 |
+
"HAUS",
|
| 554 |
+
"HBO",
|
| 555 |
+
"HDFC",
|
| 556 |
+
"HDFCBANK",
|
| 557 |
+
"HEALTH",
|
| 558 |
+
"HEALTHCARE",
|
| 559 |
+
"HELP",
|
| 560 |
+
"HELSINKI",
|
| 561 |
+
"HERE",
|
| 562 |
+
"HERMES",
|
| 563 |
+
"HGTV",
|
| 564 |
+
"HIPHOP",
|
| 565 |
+
"HISAMITSU",
|
| 566 |
+
"HITACHI",
|
| 567 |
+
"HIV",
|
| 568 |
+
"HK",
|
| 569 |
+
"HKT",
|
| 570 |
+
"HM",
|
| 571 |
+
"HN",
|
| 572 |
+
"HOCKEY",
|
| 573 |
+
"HOLDINGS",
|
| 574 |
+
"HOLIDAY",
|
| 575 |
+
"HOMEDEPOT",
|
| 576 |
+
"HOMEGOODS",
|
| 577 |
+
"HOMES",
|
| 578 |
+
"HOMESENSE",
|
| 579 |
+
"HONDA",
|
| 580 |
+
"HORSE",
|
| 581 |
+
"HOSPITAL",
|
| 582 |
+
"HOST",
|
| 583 |
+
"HOSTING",
|
| 584 |
+
"HOT",
|
| 585 |
+
"HOTELES",
|
| 586 |
+
"HOTELS",
|
| 587 |
+
"HOTMAIL",
|
| 588 |
+
"HOUSE",
|
| 589 |
+
"HOW",
|
| 590 |
+
"HR",
|
| 591 |
+
"HSBC",
|
| 592 |
+
"HT",
|
| 593 |
+
"HU",
|
| 594 |
+
"HUGHES",
|
| 595 |
+
"HYATT",
|
| 596 |
+
"HYUNDAI",
|
| 597 |
+
"IBM",
|
| 598 |
+
"ICBC",
|
| 599 |
+
"ICE",
|
| 600 |
+
"ICU",
|
| 601 |
+
"ID",
|
| 602 |
+
"IE",
|
| 603 |
+
"IEEE",
|
| 604 |
+
"IFM",
|
| 605 |
+
"IKANO",
|
| 606 |
+
"IL",
|
| 607 |
+
"IM",
|
| 608 |
+
"IMAMAT",
|
| 609 |
+
"IMDB",
|
| 610 |
+
"IMMO",
|
| 611 |
+
"IMMOBILIEN",
|
| 612 |
+
"IN",
|
| 613 |
+
"INC",
|
| 614 |
+
"INDUSTRIES",
|
| 615 |
+
"INFINITI",
|
| 616 |
+
"INFO",
|
| 617 |
+
"ING",
|
| 618 |
+
"INK",
|
| 619 |
+
"INSTITUTE",
|
| 620 |
+
"INSURANCE",
|
| 621 |
+
"INSURE",
|
| 622 |
+
"INT",
|
| 623 |
+
"INTERNATIONAL",
|
| 624 |
+
"INTUIT",
|
| 625 |
+
"INVESTMENTS",
|
| 626 |
+
"IO",
|
| 627 |
+
"IPIRANGA",
|
| 628 |
+
"IQ",
|
| 629 |
+
"IR",
|
| 630 |
+
"IRISH",
|
| 631 |
+
"IS",
|
| 632 |
+
"ISMAILI",
|
| 633 |
+
"IST",
|
| 634 |
+
"ISTANBUL",
|
| 635 |
+
"IT",
|
| 636 |
+
"ITAU",
|
| 637 |
+
"ITV",
|
| 638 |
+
"IVECO",
|
| 639 |
+
"JAGUAR",
|
| 640 |
+
"JAVA",
|
| 641 |
+
"JCB",
|
| 642 |
+
"JCP",
|
| 643 |
+
"JE",
|
| 644 |
+
"JEEP",
|
| 645 |
+
"JETZT",
|
| 646 |
+
"JEWELRY",
|
| 647 |
+
"JIO",
|
| 648 |
+
"JLL",
|
| 649 |
+
"JM",
|
| 650 |
+
"JMP",
|
| 651 |
+
"JNJ",
|
| 652 |
+
"JO",
|
| 653 |
+
"JOBS",
|
| 654 |
+
"JOBURG",
|
| 655 |
+
"JOT",
|
| 656 |
+
"JOY",
|
| 657 |
+
"JP",
|
| 658 |
+
"JPMORGAN",
|
| 659 |
+
"JPRS",
|
| 660 |
+
"JUEGOS",
|
| 661 |
+
"JUNIPER",
|
| 662 |
+
"KAUFEN",
|
| 663 |
+
"KDDI",
|
| 664 |
+
"KE",
|
| 665 |
+
"KERRYHOTELS",
|
| 666 |
+
"KERRYLOGISTICS",
|
| 667 |
+
"KERRYPROPERTIES",
|
| 668 |
+
"KFH",
|
| 669 |
+
"KG",
|
| 670 |
+
"KH",
|
| 671 |
+
"KI",
|
| 672 |
+
"KIA",
|
| 673 |
+
"KIM",
|
| 674 |
+
"KINDER",
|
| 675 |
+
"KINDLE",
|
| 676 |
+
"KITCHEN",
|
| 677 |
+
"KIWI",
|
| 678 |
+
"KM",
|
| 679 |
+
"KN",
|
| 680 |
+
"KOELN",
|
| 681 |
+
"KOMATSU",
|
| 682 |
+
"KOSHER",
|
| 683 |
+
"KP",
|
| 684 |
+
"KPMG",
|
| 685 |
+
"KPN",
|
| 686 |
+
"KR",
|
| 687 |
+
"KRD",
|
| 688 |
+
"KRED",
|
| 689 |
+
"KUOKGROUP",
|
| 690 |
+
"KW",
|
| 691 |
+
"KY",
|
| 692 |
+
"KYOTO",
|
| 693 |
+
"KZ",
|
| 694 |
+
"LA",
|
| 695 |
+
"LACAIXA",
|
| 696 |
+
"LAMBORGHINI",
|
| 697 |
+
"LAMER",
|
| 698 |
+
"LANCASTER",
|
| 699 |
+
"LANCIA",
|
| 700 |
+
"LAND",
|
| 701 |
+
"LANDROVER",
|
| 702 |
+
"LANXESS",
|
| 703 |
+
"LASALLE",
|
| 704 |
+
"LAT",
|
| 705 |
+
"LATINO",
|
| 706 |
+
"LATROBE",
|
| 707 |
+
"LAW",
|
| 708 |
+
"LAWYER",
|
| 709 |
+
"LB",
|
| 710 |
+
"LC",
|
| 711 |
+
"LDS",
|
| 712 |
+
"LEASE",
|
| 713 |
+
"LECLERC",
|
| 714 |
+
"LEFRAK",
|
| 715 |
+
"LEGAL",
|
| 716 |
+
"LEGO",
|
| 717 |
+
"LEXUS",
|
| 718 |
+
"LGBT",
|
| 719 |
+
"LI",
|
| 720 |
+
"LIDL",
|
| 721 |
+
"LIFE",
|
| 722 |
+
"LIFEINSURANCE",
|
| 723 |
+
"LIFESTYLE",
|
| 724 |
+
"LIGHTING",
|
| 725 |
+
"LIKE",
|
| 726 |
+
"LILLY",
|
| 727 |
+
"LIMITED",
|
| 728 |
+
"LIMO",
|
| 729 |
+
"LINCOLN",
|
| 730 |
+
"LINDE",
|
| 731 |
+
"LINK",
|
| 732 |
+
"LIPSY",
|
| 733 |
+
"LIVE",
|
| 734 |
+
"LIVING",
|
| 735 |
+
"LIXIL",
|
| 736 |
+
"LK",
|
| 737 |
+
"LLC",
|
| 738 |
+
"LLP",
|
| 739 |
+
"LOAN",
|
| 740 |
+
"LOANS",
|
| 741 |
+
"LOCKER",
|
| 742 |
+
"LOCUS",
|
| 743 |
+
"LOFT",
|
| 744 |
+
"LOL",
|
| 745 |
+
"LONDON",
|
| 746 |
+
"LOTTE",
|
| 747 |
+
"LOTTO",
|
| 748 |
+
"LOVE",
|
| 749 |
+
"LPL",
|
| 750 |
+
"LPLFINANCIAL",
|
| 751 |
+
"LR",
|
| 752 |
+
"LS",
|
| 753 |
+
"LT",
|
| 754 |
+
"LTD",
|
| 755 |
+
"LTDA",
|
| 756 |
+
"LU",
|
| 757 |
+
"LUNDBECK",
|
| 758 |
+
"LUPIN",
|
| 759 |
+
"LUXE",
|
| 760 |
+
"LUXURY",
|
| 761 |
+
"LV",
|
| 762 |
+
"LY",
|
| 763 |
+
"MA",
|
| 764 |
+
"MACYS",
|
| 765 |
+
"MADRID",
|
| 766 |
+
"MAIF",
|
| 767 |
+
"MAISON",
|
| 768 |
+
"MAKEUP",
|
| 769 |
+
"MAN",
|
| 770 |
+
"MANAGEMENT",
|
| 771 |
+
"MANGO",
|
| 772 |
+
"MAP",
|
| 773 |
+
"MARKET",
|
| 774 |
+
"MARKETING",
|
| 775 |
+
"MARKETS",
|
| 776 |
+
"MARRIOTT",
|
| 777 |
+
"MARSHALLS",
|
| 778 |
+
"MASERATI",
|
| 779 |
+
"MATTEL",
|
| 780 |
+
"MBA",
|
| 781 |
+
"MC",
|
| 782 |
+
"MCKINSEY",
|
| 783 |
+
"MD",
|
| 784 |
+
"ME",
|
| 785 |
+
"MED",
|
| 786 |
+
"MEDIA",
|
| 787 |
+
"MEET",
|
| 788 |
+
"MELBOURNE",
|
| 789 |
+
"MEME",
|
| 790 |
+
"MEMORIAL",
|
| 791 |
+
"MEN",
|
| 792 |
+
"MENU",
|
| 793 |
+
"MERCKMSD",
|
| 794 |
+
"MG",
|
| 795 |
+
"MH",
|
| 796 |
+
"MIAMI",
|
| 797 |
+
"MICROSOFT",
|
| 798 |
+
"MIL",
|
| 799 |
+
"MINI",
|
| 800 |
+
"MINT",
|
| 801 |
+
"MIT",
|
| 802 |
+
"MITSUBISHI",
|
| 803 |
+
"MK",
|
| 804 |
+
"ML",
|
| 805 |
+
"MLB",
|
| 806 |
+
"MLS",
|
| 807 |
+
"MM",
|
| 808 |
+
"MMA",
|
| 809 |
+
"MN",
|
| 810 |
+
"MO",
|
| 811 |
+
"MOBI",
|
| 812 |
+
"MOBILE",
|
| 813 |
+
"MODA",
|
| 814 |
+
"MOE",
|
| 815 |
+
"MOI",
|
| 816 |
+
"MOM",
|
| 817 |
+
"MONASH",
|
| 818 |
+
"MONEY",
|
| 819 |
+
"MONSTER",
|
| 820 |
+
"MORMON",
|
| 821 |
+
"MORTGAGE",
|
| 822 |
+
"MOSCOW",
|
| 823 |
+
"MOTO",
|
| 824 |
+
"MOTORCYCLES",
|
| 825 |
+
"MOV",
|
| 826 |
+
"MOVIE",
|
| 827 |
+
"MP",
|
| 828 |
+
"MQ",
|
| 829 |
+
"MR",
|
| 830 |
+
"MS",
|
| 831 |
+
"MSD",
|
| 832 |
+
"MT",
|
| 833 |
+
"MTN",
|
| 834 |
+
"MTR",
|
| 835 |
+
"MU",
|
| 836 |
+
"MUSEUM",
|
| 837 |
+
"MUTUAL",
|
| 838 |
+
"MV",
|
| 839 |
+
"MW",
|
| 840 |
+
"MX",
|
| 841 |
+
"MY",
|
| 842 |
+
"MZ",
|
| 843 |
+
"NA",
|
| 844 |
+
"NAB",
|
| 845 |
+
"NAGOYA",
|
| 846 |
+
"NAME",
|
| 847 |
+
"NATIONWIDE",
|
| 848 |
+
"NATURA",
|
| 849 |
+
"NAVY",
|
| 850 |
+
"NBA",
|
| 851 |
+
"NC",
|
| 852 |
+
"NE",
|
| 853 |
+
"NEC",
|
| 854 |
+
"NET",
|
| 855 |
+
"NETBANK",
|
| 856 |
+
"NETFLIX",
|
| 857 |
+
"NETWORK",
|
| 858 |
+
"NEUSTAR",
|
| 859 |
+
"NEW",
|
| 860 |
+
"NEWHOLLAND",
|
| 861 |
+
"NEWS",
|
| 862 |
+
"NEXT",
|
| 863 |
+
"NEXTDIRECT",
|
| 864 |
+
"NEXUS",
|
| 865 |
+
"NF",
|
| 866 |
+
"NFL",
|
| 867 |
+
"NG",
|
| 868 |
+
"NGO",
|
| 869 |
+
"NHK",
|
| 870 |
+
"NI",
|
| 871 |
+
"NICO",
|
| 872 |
+
"NIKE",
|
| 873 |
+
"NIKON",
|
| 874 |
+
"NINJA",
|
| 875 |
+
"NISSAN",
|
| 876 |
+
"NISSAY",
|
| 877 |
+
"NL",
|
| 878 |
+
"NO",
|
| 879 |
+
"NOKIA",
|
| 880 |
+
"NORTHWESTERNMUTUAL",
|
| 881 |
+
"NORTON",
|
| 882 |
+
"NOW",
|
| 883 |
+
"NOWRUZ",
|
| 884 |
+
"NOWTV",
|
| 885 |
+
"NP",
|
| 886 |
+
"NR",
|
| 887 |
+
"NRA",
|
| 888 |
+
"NRW",
|
| 889 |
+
"NTT",
|
| 890 |
+
"NU",
|
| 891 |
+
"NYC",
|
| 892 |
+
"NZ",
|
| 893 |
+
"OBI",
|
| 894 |
+
"OBSERVER",
|
| 895 |
+
"OFF",
|
| 896 |
+
"OFFICE",
|
| 897 |
+
"OKINAWA",
|
| 898 |
+
"OLAYAN",
|
| 899 |
+
"OLAYANGROUP",
|
| 900 |
+
"OLDNAVY",
|
| 901 |
+
"OLLO",
|
| 902 |
+
"OM",
|
| 903 |
+
"OMEGA",
|
| 904 |
+
"ONE",
|
| 905 |
+
"ONG",
|
| 906 |
+
"ONL",
|
| 907 |
+
"ONLINE",
|
| 908 |
+
"ONYOURSIDE",
|
| 909 |
+
"OOO",
|
| 910 |
+
"OPEN",
|
| 911 |
+
"ORACLE",
|
| 912 |
+
"ORANGE",
|
| 913 |
+
"ORG",
|
| 914 |
+
"ORGANIC",
|
| 915 |
+
"ORIGINS",
|
| 916 |
+
"OSAKA",
|
| 917 |
+
"OTSUKA",
|
| 918 |
+
"OTT",
|
| 919 |
+
"OVH",
|
| 920 |
+
"PA",
|
| 921 |
+
"PAGE",
|
| 922 |
+
"PANASONIC",
|
| 923 |
+
"PARIS",
|
| 924 |
+
"PARS",
|
| 925 |
+
"PARTNERS",
|
| 926 |
+
"PARTS",
|
| 927 |
+
"PARTY",
|
| 928 |
+
"PASSAGENS",
|
| 929 |
+
"PAY",
|
| 930 |
+
"PCCW",
|
| 931 |
+
"PE",
|
| 932 |
+
"PET",
|
| 933 |
+
"PF",
|
| 934 |
+
"PFIZER",
|
| 935 |
+
"PG",
|
| 936 |
+
"PH",
|
| 937 |
+
"PHARMACY",
|
| 938 |
+
"PHD",
|
| 939 |
+
"PHILIPS",
|
| 940 |
+
"PHONE",
|
| 941 |
+
"PHOTO",
|
| 942 |
+
"PHOTOGRAPHY",
|
| 943 |
+
"PHOTOS",
|
| 944 |
+
"PHYSIO",
|
| 945 |
+
"PICS",
|
| 946 |
+
"PICTET",
|
| 947 |
+
"PICTURES",
|
| 948 |
+
"PID",
|
| 949 |
+
"PIN",
|
| 950 |
+
"PING",
|
| 951 |
+
"PINK",
|
| 952 |
+
"PIONEER",
|
| 953 |
+
"PIZZA",
|
| 954 |
+
"PK",
|
| 955 |
+
"PL",
|
| 956 |
+
"PLACE",
|
| 957 |
+
"PLAY",
|
| 958 |
+
"PLAYSTATION",
|
| 959 |
+
"PLUMBING",
|
| 960 |
+
"PLUS",
|
| 961 |
+
"PM",
|
| 962 |
+
"PN",
|
| 963 |
+
"PNC",
|
| 964 |
+
"POHL",
|
| 965 |
+
"POKER",
|
| 966 |
+
"POLITIE",
|
| 967 |
+
"PORN",
|
| 968 |
+
"POST",
|
| 969 |
+
"PR",
|
| 970 |
+
"PRAMERICA",
|
| 971 |
+
"PRAXI",
|
| 972 |
+
"PRESS",
|
| 973 |
+
"PRIME",
|
| 974 |
+
"PRO",
|
| 975 |
+
"PROD",
|
| 976 |
+
"PRODUCTIONS",
|
| 977 |
+
"PROF",
|
| 978 |
+
"PROGRESSIVE",
|
| 979 |
+
"PROMO",
|
| 980 |
+
"PROPERTIES",
|
| 981 |
+
"PROPERTY",
|
| 982 |
+
"PROTECTION",
|
| 983 |
+
"PRU",
|
| 984 |
+
"PRUDENTIAL",
|
| 985 |
+
"PS",
|
| 986 |
+
"PT",
|
| 987 |
+
"PUB",
|
| 988 |
+
"PW",
|
| 989 |
+
"PWC",
|
| 990 |
+
"PY",
|
| 991 |
+
"QA",
|
| 992 |
+
"QPON",
|
| 993 |
+
"QUEBEC",
|
| 994 |
+
"QUEST",
|
| 995 |
+
"QVC",
|
| 996 |
+
"RACING",
|
| 997 |
+
"RADIO",
|
| 998 |
+
"RAID",
|
| 999 |
+
"RE",
|
| 1000 |
+
"READ",
|
| 1001 |
+
"REALESTATE",
|
| 1002 |
+
"REALTOR",
|
| 1003 |
+
"REALTY",
|
| 1004 |
+
"RECIPES",
|
| 1005 |
+
"RED",
|
| 1006 |
+
"REDSTONE",
|
| 1007 |
+
"REDUMBRELLA",
|
| 1008 |
+
"REHAB",
|
| 1009 |
+
"REISE",
|
| 1010 |
+
"REISEN",
|
| 1011 |
+
"REIT",
|
| 1012 |
+
"RELIANCE",
|
| 1013 |
+
"REN",
|
| 1014 |
+
"RENT",
|
| 1015 |
+
"RENTALS",
|
| 1016 |
+
"REPAIR",
|
| 1017 |
+
"REPORT",
|
| 1018 |
+
"REPUBLICAN",
|
| 1019 |
+
"REST",
|
| 1020 |
+
"RESTAURANT",
|
| 1021 |
+
"REVIEW",
|
| 1022 |
+
"REVIEWS",
|
| 1023 |
+
"REXROTH",
|
| 1024 |
+
"RICH",
|
| 1025 |
+
"RICHARDLI",
|
| 1026 |
+
"RICOH",
|
| 1027 |
+
"RIL",
|
| 1028 |
+
"RIO",
|
| 1029 |
+
"RIP",
|
| 1030 |
+
"RMIT",
|
| 1031 |
+
"RO",
|
| 1032 |
+
"ROCHER",
|
| 1033 |
+
"ROCKS",
|
| 1034 |
+
"RODEO",
|
| 1035 |
+
"ROGERS",
|
| 1036 |
+
"ROOM",
|
| 1037 |
+
"RS",
|
| 1038 |
+
"RSVP",
|
| 1039 |
+
"RU",
|
| 1040 |
+
"RUGBY",
|
| 1041 |
+
"RUHR",
|
| 1042 |
+
"RUN",
|
| 1043 |
+
"RW",
|
| 1044 |
+
"RWE",
|
| 1045 |
+
"RYUKYU",
|
| 1046 |
+
"SA",
|
| 1047 |
+
"SAARLAND",
|
| 1048 |
+
"SAFE",
|
| 1049 |
+
"SAFETY",
|
| 1050 |
+
"SAKURA",
|
| 1051 |
+
"SALE",
|
| 1052 |
+
"SALON",
|
| 1053 |
+
"SAMSCLUB",
|
| 1054 |
+
"SAMSUNG",
|
| 1055 |
+
"SANDVIK",
|
| 1056 |
+
"SANDVIKCOROMANT",
|
| 1057 |
+
"SANOFI",
|
| 1058 |
+
"SAP",
|
| 1059 |
+
"SARL",
|
| 1060 |
+
"SAS",
|
| 1061 |
+
"SAVE",
|
| 1062 |
+
"SAXO",
|
| 1063 |
+
"SB",
|
| 1064 |
+
"SBI",
|
| 1065 |
+
"SBS",
|
| 1066 |
+
"SC",
|
| 1067 |
+
"SCA",
|
| 1068 |
+
"SCB",
|
| 1069 |
+
"SCHAEFFLER",
|
| 1070 |
+
"SCHMIDT",
|
| 1071 |
+
"SCHOLARSHIPS",
|
| 1072 |
+
"SCHOOL",
|
| 1073 |
+
"SCHULE",
|
| 1074 |
+
"SCHWARZ",
|
| 1075 |
+
"SCIENCE",
|
| 1076 |
+
"SCJOHNSON",
|
| 1077 |
+
"SCOT",
|
| 1078 |
+
"SD",
|
| 1079 |
+
"SE",
|
| 1080 |
+
"SEARCH",
|
| 1081 |
+
"SEAT",
|
| 1082 |
+
"SECURE",
|
| 1083 |
+
"SECURITY",
|
| 1084 |
+
"SEEK",
|
| 1085 |
+
"SELECT",
|
| 1086 |
+
"SENER",
|
| 1087 |
+
"SERVICES",
|
| 1088 |
+
"SES",
|
| 1089 |
+
"SEVEN",
|
| 1090 |
+
"SEW",
|
| 1091 |
+
"SEX",
|
| 1092 |
+
"SEXY",
|
| 1093 |
+
"SFR",
|
| 1094 |
+
"SG",
|
| 1095 |
+
"SH",
|
| 1096 |
+
"SHANGRILA",
|
| 1097 |
+
"SHARP",
|
| 1098 |
+
"SHAW",
|
| 1099 |
+
"SHELL",
|
| 1100 |
+
"SHIA",
|
| 1101 |
+
"SHIKSHA",
|
| 1102 |
+
"SHOES",
|
| 1103 |
+
"SHOP",
|
| 1104 |
+
"SHOPPING",
|
| 1105 |
+
"SHOUJI",
|
| 1106 |
+
"SHOW",
|
| 1107 |
+
"SHOWTIME",
|
| 1108 |
+
"SHRIRAM",
|
| 1109 |
+
"SI",
|
| 1110 |
+
"SILK",
|
| 1111 |
+
"SINA",
|
| 1112 |
+
"SINGLES",
|
| 1113 |
+
"SITE",
|
| 1114 |
+
"SJ",
|
| 1115 |
+
"SK",
|
| 1116 |
+
"SKI",
|
| 1117 |
+
"SKIN",
|
| 1118 |
+
"SKY",
|
| 1119 |
+
"SKYPE",
|
| 1120 |
+
"SL",
|
| 1121 |
+
"SLING",
|
| 1122 |
+
"SM",
|
| 1123 |
+
"SMART",
|
| 1124 |
+
"SMILE",
|
| 1125 |
+
"SN",
|
| 1126 |
+
"SNCF",
|
| 1127 |
+
"SO",
|
| 1128 |
+
"SOCCER",
|
| 1129 |
+
"SOCIAL",
|
| 1130 |
+
"SOFTBANK",
|
| 1131 |
+
"SOFTWARE",
|
| 1132 |
+
"SOHU",
|
| 1133 |
+
"SOLAR",
|
| 1134 |
+
"SOLUTIONS",
|
| 1135 |
+
"SONG",
|
| 1136 |
+
"SONY",
|
| 1137 |
+
"SOY",
|
| 1138 |
+
"SPA",
|
| 1139 |
+
"SPACE",
|
| 1140 |
+
"SPORT",
|
| 1141 |
+
"SPOT",
|
| 1142 |
+
"SPREADBETTING",
|
| 1143 |
+
"SR",
|
| 1144 |
+
"SRL",
|
| 1145 |
+
"SS",
|
| 1146 |
+
"ST",
|
| 1147 |
+
"STADA",
|
| 1148 |
+
"STAPLES",
|
| 1149 |
+
"STAR",
|
| 1150 |
+
"STATEBANK",
|
| 1151 |
+
"STATEFARM",
|
| 1152 |
+
"STC",
|
| 1153 |
+
"STCGROUP",
|
| 1154 |
+
"STOCKHOLM",
|
| 1155 |
+
"STORAGE",
|
| 1156 |
+
"STORE",
|
| 1157 |
+
"STREAM",
|
| 1158 |
+
"STUDIO",
|
| 1159 |
+
"STUDY",
|
| 1160 |
+
"STYLE",
|
| 1161 |
+
"SU",
|
| 1162 |
+
"SUCKS",
|
| 1163 |
+
"SUPPLIES",
|
| 1164 |
+
"SUPPLY",
|
| 1165 |
+
"SUPPORT",
|
| 1166 |
+
"SURF",
|
| 1167 |
+
"SURGERY",
|
| 1168 |
+
"SUZUKI",
|
| 1169 |
+
"SV",
|
| 1170 |
+
"SWATCH",
|
| 1171 |
+
"SWIFTCOVER",
|
| 1172 |
+
"SWISS",
|
| 1173 |
+
"SX",
|
| 1174 |
+
"SY",
|
| 1175 |
+
"SYDNEY",
|
| 1176 |
+
"SYSTEMS",
|
| 1177 |
+
"SZ",
|
| 1178 |
+
"TAB",
|
| 1179 |
+
"TAIPEI",
|
| 1180 |
+
"TALK",
|
| 1181 |
+
"TAOBAO",
|
| 1182 |
+
"TARGET",
|
| 1183 |
+
"TATAMOTORS",
|
| 1184 |
+
"TATAR",
|
| 1185 |
+
"TATTOO",
|
| 1186 |
+
"TAX",
|
| 1187 |
+
"TAXI",
|
| 1188 |
+
"TC",
|
| 1189 |
+
"TCI",
|
| 1190 |
+
"TD",
|
| 1191 |
+
"TDK",
|
| 1192 |
+
"TEAM",
|
| 1193 |
+
"TECH",
|
| 1194 |
+
"TECHNOLOGY",
|
| 1195 |
+
"TEL",
|
| 1196 |
+
"TEMASEK",
|
| 1197 |
+
"TENNIS",
|
| 1198 |
+
"TEVA",
|
| 1199 |
+
"TF",
|
| 1200 |
+
"TG",
|
| 1201 |
+
"TH",
|
| 1202 |
+
"THD",
|
| 1203 |
+
"THEATER",
|
| 1204 |
+
"THEATRE",
|
| 1205 |
+
"TIAA",
|
| 1206 |
+
"TICKETS",
|
| 1207 |
+
"TIENDA",
|
| 1208 |
+
"TIFFANY",
|
| 1209 |
+
"TIPS",
|
| 1210 |
+
"TIRES",
|
| 1211 |
+
"TIROL",
|
| 1212 |
+
"TJ",
|
| 1213 |
+
"TJMAXX",
|
| 1214 |
+
"TJX",
|
| 1215 |
+
"TK",
|
| 1216 |
+
"TKMAXX",
|
| 1217 |
+
"TL",
|
| 1218 |
+
"TM",
|
| 1219 |
+
"TMALL",
|
| 1220 |
+
"TN",
|
| 1221 |
+
"TO",
|
| 1222 |
+
"TODAY",
|
| 1223 |
+
"TOKYO",
|
| 1224 |
+
"TOOLS",
|
| 1225 |
+
"TOP",
|
| 1226 |
+
"TORAY",
|
| 1227 |
+
"TOSHIBA",
|
| 1228 |
+
"TOTAL",
|
| 1229 |
+
"TOURS",
|
| 1230 |
+
"TOWN",
|
| 1231 |
+
"TOYOTA",
|
| 1232 |
+
"TOYS",
|
| 1233 |
+
"TR",
|
| 1234 |
+
"TRADE",
|
| 1235 |
+
"TRADING",
|
| 1236 |
+
"TRAINING",
|
| 1237 |
+
"TRAVEL",
|
| 1238 |
+
"TRAVELCHANNEL",
|
| 1239 |
+
"TRAVELERS",
|
| 1240 |
+
"TRAVELERSINSURANCE",
|
| 1241 |
+
"TRUST",
|
| 1242 |
+
"TRV",
|
| 1243 |
+
"TT",
|
| 1244 |
+
"TUBE",
|
| 1245 |
+
"TUI",
|
| 1246 |
+
"TUNES",
|
| 1247 |
+
"TUSHU",
|
| 1248 |
+
"TV",
|
| 1249 |
+
"TVS",
|
| 1250 |
+
"TW",
|
| 1251 |
+
"TZ",
|
| 1252 |
+
"UA",
|
| 1253 |
+
"UBANK",
|
| 1254 |
+
"UBS",
|
| 1255 |
+
"UG",
|
| 1256 |
+
"UK",
|
| 1257 |
+
"UNICOM",
|
| 1258 |
+
"UNIVERSITY",
|
| 1259 |
+
"UNO",
|
| 1260 |
+
"UOL",
|
| 1261 |
+
"UPS",
|
| 1262 |
+
"US",
|
| 1263 |
+
"UY",
|
| 1264 |
+
"UZ",
|
| 1265 |
+
"VA",
|
| 1266 |
+
"VACATIONS",
|
| 1267 |
+
"VANA",
|
| 1268 |
+
"VANGUARD",
|
| 1269 |
+
"VC",
|
| 1270 |
+
"VE",
|
| 1271 |
+
"VEGAS",
|
| 1272 |
+
"VENTURES",
|
| 1273 |
+
"VERISIGN",
|
| 1274 |
+
"VERSICHERUNG",
|
| 1275 |
+
"VET",
|
| 1276 |
+
"VG",
|
| 1277 |
+
"VI",
|
| 1278 |
+
"VIAJES",
|
| 1279 |
+
"VIDEO",
|
| 1280 |
+
"VIG",
|
| 1281 |
+
"VIKING",
|
| 1282 |
+
"VILLAS",
|
| 1283 |
+
"VIN",
|
| 1284 |
+
"VIP",
|
| 1285 |
+
"VIRGIN",
|
| 1286 |
+
"VISA",
|
| 1287 |
+
"VISION",
|
| 1288 |
+
"VIVA",
|
| 1289 |
+
"VIVO",
|
| 1290 |
+
"VLAANDEREN",
|
| 1291 |
+
"VN",
|
| 1292 |
+
"VODKA",
|
| 1293 |
+
"VOLKSWAGEN",
|
| 1294 |
+
"VOLVO",
|
| 1295 |
+
"VOTE",
|
| 1296 |
+
"VOTING",
|
| 1297 |
+
"VOTO",
|
| 1298 |
+
"VOYAGE",
|
| 1299 |
+
"VU",
|
| 1300 |
+
"VUELOS",
|
| 1301 |
+
"WALES",
|
| 1302 |
+
"WALMART",
|
| 1303 |
+
"WALTER",
|
| 1304 |
+
"WANG",
|
| 1305 |
+
"WANGGOU",
|
| 1306 |
+
"WATCH",
|
| 1307 |
+
"WATCHES",
|
| 1308 |
+
"WEATHER",
|
| 1309 |
+
"WEATHERCHANNEL",
|
| 1310 |
+
"WEBCAM",
|
| 1311 |
+
"WEBER",
|
| 1312 |
+
"WEBSITE",
|
| 1313 |
+
"WED",
|
| 1314 |
+
"WEDDING",
|
| 1315 |
+
"WEIBO",
|
| 1316 |
+
"WEIR",
|
| 1317 |
+
"WF",
|
| 1318 |
+
"WHOSWHO",
|
| 1319 |
+
"WIEN",
|
| 1320 |
+
"WIKI",
|
| 1321 |
+
"WILLIAMHILL",
|
| 1322 |
+
"WIN",
|
| 1323 |
+
"WINDOWS",
|
| 1324 |
+
"WINE",
|
| 1325 |
+
"WINNERS",
|
| 1326 |
+
"WME",
|
| 1327 |
+
"WOLTERSKLUWER",
|
| 1328 |
+
"WOODSIDE",
|
| 1329 |
+
"WORK",
|
| 1330 |
+
"WORKS",
|
| 1331 |
+
"WORLD",
|
| 1332 |
+
"WOW",
|
| 1333 |
+
"WS",
|
| 1334 |
+
"WTC",
|
| 1335 |
+
"WTF",
|
| 1336 |
+
"XBOX",
|
| 1337 |
+
"XEROX",
|
| 1338 |
+
"XFINITY",
|
| 1339 |
+
"XIHUAN",
|
| 1340 |
+
"XIN",
|
| 1341 |
+
"XN--11B4C3D",
|
| 1342 |
+
"XN--1CK2E1B",
|
| 1343 |
+
"XN--1QQW23A",
|
| 1344 |
+
"XN--2SCRJ9C",
|
| 1345 |
+
"XN--30RR7Y",
|
| 1346 |
+
"XN--3BST00M",
|
| 1347 |
+
"XN--3DS443G",
|
| 1348 |
+
"XN--3E0B707E",
|
| 1349 |
+
"XN--3HCRJ9C",
|
| 1350 |
+
"XN--3OQ18VL8PN36A",
|
| 1351 |
+
"XN--3PXU8K",
|
| 1352 |
+
"XN--42C2D9A",
|
| 1353 |
+
"XN--45BR5CYL",
|
| 1354 |
+
"XN--45BRJ9C",
|
| 1355 |
+
"XN--45Q11C",
|
| 1356 |
+
"XN--4GBRIM",
|
| 1357 |
+
"XN--54B7FTA0CC",
|
| 1358 |
+
"XN--55QW42G",
|
| 1359 |
+
"XN--55QX5D",
|
| 1360 |
+
"XN--5SU34J936BGSG",
|
| 1361 |
+
"XN--5TZM5G",
|
| 1362 |
+
"XN--6FRZ82G",
|
| 1363 |
+
"XN--6QQ986B3XL",
|
| 1364 |
+
"XN--80ADXHKS",
|
| 1365 |
+
"XN--80AO21A",
|
| 1366 |
+
"XN--80AQECDR1A",
|
| 1367 |
+
"XN--80ASEHDB",
|
| 1368 |
+
"XN--80ASWG",
|
| 1369 |
+
"XN--8Y0A063A",
|
| 1370 |
+
"XN--90A3AC",
|
| 1371 |
+
"XN--90AE",
|
| 1372 |
+
"XN--90AIS",
|
| 1373 |
+
"XN--9DBQ2A",
|
| 1374 |
+
"XN--9ET52U",
|
| 1375 |
+
"XN--9KRT00A",
|
| 1376 |
+
"XN--B4W605FERD",
|
| 1377 |
+
"XN--BCK1B9A5DRE4C",
|
| 1378 |
+
"XN--C1AVG",
|
| 1379 |
+
"XN--C2BR7G",
|
| 1380 |
+
"XN--CCK2B3B",
|
| 1381 |
+
"XN--CCKWCXETD",
|
| 1382 |
+
"XN--CG4BKI",
|
| 1383 |
+
"XN--CLCHC0EA0B2G2A9GCD",
|
| 1384 |
+
"XN--CZR694B",
|
| 1385 |
+
"XN--CZRS0T",
|
| 1386 |
+
"XN--CZRU2D",
|
| 1387 |
+
"XN--D1ACJ3B",
|
| 1388 |
+
"XN--D1ALF",
|
| 1389 |
+
"XN--E1A4C",
|
| 1390 |
+
"XN--ECKVDTC9D",
|
| 1391 |
+
"XN--EFVY88H",
|
| 1392 |
+
"XN--FCT429K",
|
| 1393 |
+
"XN--FHBEI",
|
| 1394 |
+
"XN--FIQ228C5HS",
|
| 1395 |
+
"XN--FIQ64B",
|
| 1396 |
+
"XN--FIQS8S",
|
| 1397 |
+
"XN--FIQZ9S",
|
| 1398 |
+
"XN--FJQ720A",
|
| 1399 |
+
"XN--FLW351E",
|
| 1400 |
+
"XN--FPCRJ9C3D",
|
| 1401 |
+
"XN--FZC2C9E2C",
|
| 1402 |
+
"XN--FZYS8D69UVGM",
|
| 1403 |
+
"XN--G2XX48C",
|
| 1404 |
+
"XN--GCKR3F0F",
|
| 1405 |
+
"XN--GECRJ9C",
|
| 1406 |
+
"XN--GK3AT1E",
|
| 1407 |
+
"XN--H2BREG3EVE",
|
| 1408 |
+
"XN--H2BRJ9C",
|
| 1409 |
+
"XN--H2BRJ9C8C",
|
| 1410 |
+
"XN--HXT814E",
|
| 1411 |
+
"XN--I1B6B1A6A2E",
|
| 1412 |
+
"XN--IMR513N",
|
| 1413 |
+
"XN--IO0A7I",
|
| 1414 |
+
"XN--J1AEF",
|
| 1415 |
+
"XN--J1AMH",
|
| 1416 |
+
"XN--J6W193G",
|
| 1417 |
+
"XN--JLQ480N2RG",
|
| 1418 |
+
"XN--JLQ61U9W7B",
|
| 1419 |
+
"XN--JVR189M",
|
| 1420 |
+
"XN--KCRX77D1X4A",
|
| 1421 |
+
"XN--KPRW13D",
|
| 1422 |
+
"XN--KPRY57D",
|
| 1423 |
+
"XN--KPUT3I",
|
| 1424 |
+
"XN--L1ACC",
|
| 1425 |
+
"XN--LGBBAT1AD8J",
|
| 1426 |
+
"XN--MGB9AWBF",
|
| 1427 |
+
"XN--MGBA3A3EJT",
|
| 1428 |
+
"XN--MGBA3A4F16A",
|
| 1429 |
+
"XN--MGBA7C0BBN0A",
|
| 1430 |
+
"XN--MGBAAKC7DVF",
|
| 1431 |
+
"XN--MGBAAM7A8H",
|
| 1432 |
+
"XN--MGBAB2BD",
|
| 1433 |
+
"XN--MGBAH1A3HJKRD",
|
| 1434 |
+
"XN--MGBAI9AZGQP6J",
|
| 1435 |
+
"XN--MGBAYH7GPA",
|
| 1436 |
+
"XN--MGBBH1A",
|
| 1437 |
+
"XN--MGBBH1A71E",
|
| 1438 |
+
"XN--MGBC0A9AZCG",
|
| 1439 |
+
"XN--MGBCA7DZDO",
|
| 1440 |
+
"XN--MGBCPQ6GPA1A",
|
| 1441 |
+
"XN--MGBERP4A5D4AR",
|
| 1442 |
+
"XN--MGBGU82A",
|
| 1443 |
+
"XN--MGBI4ECEXP",
|
| 1444 |
+
"XN--MGBPL2FH",
|
| 1445 |
+
"XN--MGBT3DHD",
|
| 1446 |
+
"XN--MGBTX2B",
|
| 1447 |
+
"XN--MGBX4CD0AB",
|
| 1448 |
+
"XN--MIX891F",
|
| 1449 |
+
"XN--MK1BU44C",
|
| 1450 |
+
"XN--MXTQ1M",
|
| 1451 |
+
"XN--NGBC5AZD",
|
| 1452 |
+
"XN--NGBE9E0A",
|
| 1453 |
+
"XN--NGBRX",
|
| 1454 |
+
"XN--NODE",
|
| 1455 |
+
"XN--NQV7F",
|
| 1456 |
+
"XN--NQV7FS00EMA",
|
| 1457 |
+
"XN--NYQY26A",
|
| 1458 |
+
"XN--O3CW4H",
|
| 1459 |
+
"XN--OGBPF8FL",
|
| 1460 |
+
"XN--OTU796D",
|
| 1461 |
+
"XN--P1ACF",
|
| 1462 |
+
"XN--P1AI",
|
| 1463 |
+
"XN--PGBS0DH",
|
| 1464 |
+
"XN--PSSY2U",
|
| 1465 |
+
"XN--Q7CE6A",
|
| 1466 |
+
"XN--Q9JYB4C",
|
| 1467 |
+
"XN--QCKA1PMC",
|
| 1468 |
+
"XN--QXA6A",
|
| 1469 |
+
"XN--QXAM",
|
| 1470 |
+
"XN--RHQV96G",
|
| 1471 |
+
"XN--ROVU88B",
|
| 1472 |
+
"XN--RVC1E0AM3E",
|
| 1473 |
+
"XN--S9BRJ9C",
|
| 1474 |
+
"XN--SES554G",
|
| 1475 |
+
"XN--T60B56A",
|
| 1476 |
+
"XN--TCKWE",
|
| 1477 |
+
"XN--TIQ49XQYJ",
|
| 1478 |
+
"XN--UNUP4Y",
|
| 1479 |
+
"XN--VERMGENSBERATER-CTB",
|
| 1480 |
+
"XN--VERMGENSBERATUNG-PWB",
|
| 1481 |
+
"XN--VHQUV",
|
| 1482 |
+
"XN--VUQ861B",
|
| 1483 |
+
"XN--W4R85EL8FHU5DNRA",
|
| 1484 |
+
"XN--W4RS40L",
|
| 1485 |
+
"XN--WGBH1C",
|
| 1486 |
+
"XN--WGBL6A",
|
| 1487 |
+
"XN--XHQ521B",
|
| 1488 |
+
"XN--XKC2AL3HYE2A",
|
| 1489 |
+
"XN--XKC2DL3A5EE0H",
|
| 1490 |
+
"XN--Y9A3AQ",
|
| 1491 |
+
"XN--YFRO4I67O",
|
| 1492 |
+
"XN--YGBI2AMMX",
|
| 1493 |
+
"XN--ZFR164B",
|
| 1494 |
+
"XXX",
|
| 1495 |
+
"XYZ",
|
| 1496 |
+
"YACHTS",
|
| 1497 |
+
"YAHOO",
|
| 1498 |
+
"YAMAXUN",
|
| 1499 |
+
"YANDEX",
|
| 1500 |
+
"YE",
|
| 1501 |
+
"YODOBASHI",
|
| 1502 |
+
"YOGA",
|
| 1503 |
+
"YOKOHAMA",
|
| 1504 |
+
"YOU",
|
| 1505 |
+
"YOUTUBE",
|
| 1506 |
+
"YT",
|
| 1507 |
+
"YUN",
|
| 1508 |
+
"ZA",
|
| 1509 |
+
"ZAPPOS",
|
| 1510 |
+
"ZARA",
|
| 1511 |
+
"ZERO",
|
| 1512 |
+
"ZIP",
|
| 1513 |
+
"ZM",
|
| 1514 |
+
"ZONE",
|
| 1515 |
+
"ZUERICH",
|
| 1516 |
+
"ZW",
|
| 1517 |
+
]
|
mplug_owl2/lib/python3.10/site-packages/linkify_it/ucre.py
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from uc_micro.categories import Cc, Cf, P, Z
|
| 2 |
+
from uc_micro.properties import Any
|
| 3 |
+
|
| 4 |
+
SRC_ANY = Any.REGEX
|
| 5 |
+
SRC_CC = Cc.REGEX
|
| 6 |
+
SRC_CF = Cf.REGEX
|
| 7 |
+
SRC_P = P.REGEX
|
| 8 |
+
SRC_Z = Z.REGEX
|
| 9 |
+
|
| 10 |
+
# \p{\Z\P\Cc\CF} (white spaces + control + format + punctuation)
|
| 11 |
+
SRC_ZPCC = "|".join([SRC_Z, SRC_P, SRC_CC])
|
| 12 |
+
|
| 13 |
+
# \p{\Z\Cc} (white spaces + control)
|
| 14 |
+
SRC_ZCC = "|".join([SRC_Z, SRC_CC])
|
| 15 |
+
|
| 16 |
+
# Experimental. List of chars, completely prohibited in links
|
| 17 |
+
# because can separate it from other part of text
|
| 18 |
+
TEXT_SEPARATORS = "[><\uff5c]"
|
| 19 |
+
|
| 20 |
+
# All possible word characters (everything without punctuation, spaces & controls)
|
| 21 |
+
# Defined via punctuation & spaces to save space
|
| 22 |
+
# Should be something like \p{\L\N\S\M} (\w but without `_`)
|
| 23 |
+
SRC_PSEUDO_LETTER = "(?:(?!" + TEXT_SEPARATORS + "|" + SRC_ZPCC + ")" + SRC_ANY + ")"
|
| 24 |
+
# The same as abothe but without [0-9]
|
| 25 |
+
# var SRC_PSEUDO_LETTER_non_d = '(?:(?![0-9]|' + SRC_ZPCC + ')' + SRC_ANY + ')'
|
| 26 |
+
|
| 27 |
+
# =============================================================================
|
| 28 |
+
|
| 29 |
+
SRC_IP4 = (
|
| 30 |
+
"(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|"
|
| 31 |
+
+ "2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Prohibit any of "@/[]()" in user/pass to avoid wrong domain fetch.
|
| 35 |
+
SRC_AUTH = "(?:(?:(?!" + SRC_ZCC + "|[@/\\[\\]()]).)+@)?"
|
| 36 |
+
|
| 37 |
+
SRC_PORT = (
|
| 38 |
+
"(?::(?:6(?:[0-4]\\d{3}|5(?:[0-4]\\d{2}|5(?:[0-2]\\d|3[0-5])))|[1-5]?\\d{1,4}))?"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Allow anything in markdown spec, forbid quote (") at the first position
|
| 42 |
+
# because emails enclosed in quotes are far more common
|
| 43 |
+
SRC_EMAIL_NAME = '[\\-:&=\\+\\$,\\.a-zA-Z0-9_][\\-:&=\\+\\$,\\"\\.a-zA-Z0-9_]*'
|
| 44 |
+
|
| 45 |
+
SRC_XN = "xn--[a-z0-9\\-]{1,59}"
|
| 46 |
+
|
| 47 |
+
# More to read about domain names
|
| 48 |
+
# http:#serverfault.com/questions/638260/
|
| 49 |
+
|
| 50 |
+
# Allow letters & digits (http:#test1)
|
| 51 |
+
SRC_DOMAIN_ROOT = "(?:" + SRC_XN + "|" + SRC_PSEUDO_LETTER + "{1,63}" + ")"
|
| 52 |
+
|
| 53 |
+
SRC_DOMAIN = (
|
| 54 |
+
"(?:"
|
| 55 |
+
+ SRC_XN
|
| 56 |
+
+ "|"
|
| 57 |
+
+ "(?:"
|
| 58 |
+
+ SRC_PSEUDO_LETTER
|
| 59 |
+
+ ")"
|
| 60 |
+
+ "|"
|
| 61 |
+
+ "(?:"
|
| 62 |
+
+ SRC_PSEUDO_LETTER
|
| 63 |
+
+ "(?:-|"
|
| 64 |
+
+ SRC_PSEUDO_LETTER
|
| 65 |
+
+ "){0,61}"
|
| 66 |
+
+ SRC_PSEUDO_LETTER
|
| 67 |
+
+ ")"
|
| 68 |
+
+ ")"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
SRC_HOST = (
|
| 72 |
+
"(?:"
|
| 73 |
+
+
|
| 74 |
+
# Don't need IP check, because digits are already allowed in normal domain names
|
| 75 |
+
# SRC_IP4 +
|
| 76 |
+
# '|' +
|
| 77 |
+
"(?:(?:(?:"
|
| 78 |
+
+ SRC_DOMAIN
|
| 79 |
+
+ ")\\.)*"
|
| 80 |
+
+ SRC_DOMAIN # _root
|
| 81 |
+
+ ")"
|
| 82 |
+
+ ")"
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
TPL_HOST_FUZZY = (
|
| 86 |
+
"(?:" + SRC_IP4 + "|" + "(?:(?:(?:" + SRC_DOMAIN + ")\\.)+(?:%TLDS%))" + ")"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
TPL_HOST_NO_IP_FUZZY = "(?:(?:(?:" + SRC_DOMAIN + ")\\.)+(?:%TLDS%))"
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# =============================================================================
|
| 93 |
+
|
| 94 |
+
# Rude test fuzzy links by host, for quick deny
|
| 95 |
+
TPL_HOST_FUZZY_TEST = (
|
| 96 |
+
"localhost|www\\.|\\.\\d{1,3}\\.|(?:\\.(?:%TLDS%)(?:" + SRC_ZPCC + "|>|$))"
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _re_host_terminator(opts):
|
| 101 |
+
src_host_terminator = (
|
| 102 |
+
"(?=$|"
|
| 103 |
+
+ TEXT_SEPARATORS
|
| 104 |
+
+ "|"
|
| 105 |
+
+ SRC_ZPCC
|
| 106 |
+
+ ")"
|
| 107 |
+
+ "(?!"
|
| 108 |
+
+ ("-(?!--)|" if opts.get("---") else "-|")
|
| 109 |
+
+ "_|:\\d|\\.-|\\.(?!$|"
|
| 110 |
+
+ SRC_ZPCC
|
| 111 |
+
+ "))"
|
| 112 |
+
)
|
| 113 |
+
return src_host_terminator
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _re_src_path(opts):
|
| 117 |
+
src_path = (
|
| 118 |
+
"(?:"
|
| 119 |
+
+ "[/?#]"
|
| 120 |
+
+ "(?:"
|
| 121 |
+
+ "(?!"
|
| 122 |
+
+ SRC_ZCC
|
| 123 |
+
+ "|"
|
| 124 |
+
+ TEXT_SEPARATORS
|
| 125 |
+
+ "|[()[\\]{}.,\"'?!\\-;]).|"
|
| 126 |
+
+ "\\[(?:(?!"
|
| 127 |
+
+ SRC_ZCC
|
| 128 |
+
+ "|\\]).)*\\]|"
|
| 129 |
+
+ "\\((?:(?!"
|
| 130 |
+
+ SRC_ZCC
|
| 131 |
+
+ "|[)]).)*\\)|"
|
| 132 |
+
+ "\\{(?:(?!"
|
| 133 |
+
+ SRC_ZCC
|
| 134 |
+
+ "|[}]).)*\\}|"
|
| 135 |
+
+ '\\"(?:(?!'
|
| 136 |
+
+ SRC_ZCC
|
| 137 |
+
+ '|["]).)+\\"|'
|
| 138 |
+
+ "\\'(?:(?!"
|
| 139 |
+
+ SRC_ZCC
|
| 140 |
+
+ "|[']).)+\\'|"
|
| 141 |
+
+ "\\'(?="
|
| 142 |
+
+ SRC_PSEUDO_LETTER
|
| 143 |
+
+ "|[-])|"
|
| 144 |
+
+ "\\.{2,}[a-zA-Z0-9%/&]|"
|
| 145 |
+
# google has many dots in "google search" links (#66, #81).
|
| 146 |
+
# github has ... in commit range links,
|
| 147 |
+
# ReSTRICT to
|
| 148 |
+
# - english
|
| 149 |
+
# - percent-encoded
|
| 150 |
+
# - parts of file path
|
| 151 |
+
# - params separator
|
| 152 |
+
# until more examples found.
|
| 153 |
+
+ "\\.(?!"
|
| 154 |
+
+ SRC_ZCC
|
| 155 |
+
+ "|[.]|$)|"
|
| 156 |
+
+ ("\\-(?!--(?:[^-]|$))(?:-*)|" if opts.get("---") else "\\-+|")
|
| 157 |
+
+ ",(?!"
|
| 158 |
+
+ SRC_ZCC
|
| 159 |
+
+ "|$)|" # allow `,,,` in paths
|
| 160 |
+
+ ";(?!"
|
| 161 |
+
+ SRC_ZCC
|
| 162 |
+
+ "|$)|" # allow `,,,` in paths
|
| 163 |
+
+ "\\!+(?!"
|
| 164 |
+
+ SRC_ZCC
|
| 165 |
+
+ "|[!]|$)|" # allow `!!!` in paths, but not at the end
|
| 166 |
+
+ "\\?(?!"
|
| 167 |
+
+ SRC_ZCC
|
| 168 |
+
+ "|[?]|$)"
|
| 169 |
+
+ ")+"
|
| 170 |
+
+ "|\\/"
|
| 171 |
+
+ ")?"
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
return src_path
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def build_re(opts):
|
| 178 |
+
"""Build regex
|
| 179 |
+
|
| 180 |
+
Args:
|
| 181 |
+
opts (dict): options
|
| 182 |
+
|
| 183 |
+
Return:
|
| 184 |
+
dict: dict of regex string
|
| 185 |
+
"""
|
| 186 |
+
SRC_HOST_STRICT = SRC_HOST + _re_host_terminator(opts)
|
| 187 |
+
|
| 188 |
+
TPL_HOST_FUZZY_STRICT = TPL_HOST_FUZZY + _re_host_terminator(opts)
|
| 189 |
+
|
| 190 |
+
SRC_HOST_PORT_STRICT = SRC_HOST + SRC_PORT + _re_host_terminator(opts)
|
| 191 |
+
|
| 192 |
+
TPL_HOST_PORT_FUZZY_STRICT = TPL_HOST_FUZZY + SRC_PORT + _re_host_terminator(opts)
|
| 193 |
+
|
| 194 |
+
TPL_HOST_PORT_NO_IP_FUZZY_STRICT = (
|
| 195 |
+
TPL_HOST_NO_IP_FUZZY + SRC_PORT + _re_host_terminator(opts)
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
TPL_EMAIL_FUZZY = (
|
| 199 |
+
"(^|"
|
| 200 |
+
+ TEXT_SEPARATORS
|
| 201 |
+
+ '|"|\\(|'
|
| 202 |
+
+ SRC_ZCC
|
| 203 |
+
+ ")"
|
| 204 |
+
+ "("
|
| 205 |
+
+ SRC_EMAIL_NAME
|
| 206 |
+
+ "@"
|
| 207 |
+
+ TPL_HOST_FUZZY_STRICT
|
| 208 |
+
+ ")"
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
regex = {
|
| 212 |
+
"src_Any": SRC_ANY,
|
| 213 |
+
"src_Cc": SRC_CC,
|
| 214 |
+
"src_Cf": SRC_CF,
|
| 215 |
+
"src_Z": SRC_Z,
|
| 216 |
+
"src_P": SRC_P,
|
| 217 |
+
"src_ZPCc": SRC_ZPCC,
|
| 218 |
+
"src_ZCc": SRC_ZCC,
|
| 219 |
+
"src_pseudo_letter": SRC_PSEUDO_LETTER,
|
| 220 |
+
"src_ip4": SRC_IP4,
|
| 221 |
+
"src_auth": SRC_AUTH,
|
| 222 |
+
"src_port": SRC_PORT,
|
| 223 |
+
"src_host_terminator": _re_host_terminator(opts),
|
| 224 |
+
"src_path": _re_src_path(opts),
|
| 225 |
+
"src_email_name": SRC_EMAIL_NAME,
|
| 226 |
+
"src_xn": SRC_XN,
|
| 227 |
+
"src_domain_root": SRC_DOMAIN_ROOT,
|
| 228 |
+
"src_domain": SRC_DOMAIN,
|
| 229 |
+
"src_host": SRC_HOST,
|
| 230 |
+
"tpl_host_fuzzy": TPL_HOST_FUZZY,
|
| 231 |
+
"tpl_host_no_ip_fuzzy": TPL_HOST_NO_IP_FUZZY,
|
| 232 |
+
"src_host_strict": SRC_HOST_STRICT,
|
| 233 |
+
"tpl_host_fuzzy_strict": TPL_HOST_FUZZY_STRICT,
|
| 234 |
+
"src_host_port_strict": SRC_HOST_PORT_STRICT,
|
| 235 |
+
"tpl_host_port_fuzzy_strict": TPL_HOST_PORT_FUZZY_STRICT,
|
| 236 |
+
"tpl_host_port_no_ip_fuzzy_strict": TPL_HOST_PORT_FUZZY_STRICT,
|
| 237 |
+
# Main rules
|
| 238 |
+
"tpl_host_fuzzy_test": TPL_HOST_FUZZY_TEST,
|
| 239 |
+
"tpl_email_fuzzy": TPL_EMAIL_FUZZY,
|
| 240 |
+
# Fuzzy link can't be prepended with .:/\- and non punctuation.
|
| 241 |
+
# but can start with > (markdown blockquote)
|
| 242 |
+
"tpl_link_fuzzy": (
|
| 243 |
+
"(^|(?![.:/\\-_@])(?:[$+<=>^`|\uff5c]|"
|
| 244 |
+
+ SRC_ZPCC
|
| 245 |
+
+ "))"
|
| 246 |
+
+ "((?![$+<=>^`|\uff5c])"
|
| 247 |
+
+ TPL_HOST_PORT_FUZZY_STRICT
|
| 248 |
+
+ _re_src_path(opts)
|
| 249 |
+
+ ")"
|
| 250 |
+
),
|
| 251 |
+
# Fuzzy link can't be prepended with .:/\- and non punctuation.
|
| 252 |
+
# but can start with > (markdown blockquote)
|
| 253 |
+
"tpl_link_no_ip_fuzzy": (
|
| 254 |
+
"(^|(?![.:/\\-_@])(?:[$+<=>^`|\uff5c]|"
|
| 255 |
+
+ SRC_ZPCC
|
| 256 |
+
+ "))"
|
| 257 |
+
+ "((?![$+<=>^`|\uff5c])"
|
| 258 |
+
+ TPL_HOST_PORT_NO_IP_FUZZY_STRICT
|
| 259 |
+
+ _re_src_path(opts)
|
| 260 |
+
+ ")"
|
| 261 |
+
),
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
return regex
|
mplug_owl2/lib/python3.10/site-packages/nvidia_cufft_cu12-11.2.1.3.dist-info/RECORD
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nvidia/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 2 |
+
nvidia/__pycache__/__init__.cpython-310.pyc,,
|
| 3 |
+
nvidia/cufft/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 4 |
+
nvidia/cufft/__pycache__/__init__.cpython-310.pyc,,
|
| 5 |
+
nvidia/cufft/include/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
nvidia/cufft/include/__pycache__/__init__.cpython-310.pyc,,
|
| 7 |
+
nvidia/cufft/include/cudalibxt.h,sha256=9GDuRiOzJuO61zRDhIpWpF7XHp8FXSOIlHJNoIMwOZQ,4105
|
| 8 |
+
nvidia/cufft/include/cufft.h,sha256=OPTrbN3YvHR2HZTy4Kr_azbFUz8ZGXAkmT_1ero1y3I,13109
|
| 9 |
+
nvidia/cufft/include/cufftXt.h,sha256=bTMo9ixYPn-FnrCw2VYZ2XVwDYT7N8WrRdXp4CmBilY,11148
|
| 10 |
+
nvidia/cufft/include/cufftw.h,sha256=Uzfj1IVMlLQU_G50u84hXYX1K95HLXIwOcjQoAg5pGE,20051
|
| 11 |
+
nvidia/cufft/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 12 |
+
nvidia/cufft/lib/__pycache__/__init__.cpython-310.pyc,,
|
| 13 |
+
nvidia/cufft/lib/libcufft.so.11,sha256=85IcQTOSUkJFnr_b95AdtOv65rvP_53FzlOx_xP7Qv8,292889192
|
| 14 |
+
nvidia/cufft/lib/libcufftw.so.11,sha256=IwelrPzMm0D5iThAOCGM_q1WTNQ2M3AdMMiTBH50T0Q,974888
|
| 15 |
+
nvidia_cufft_cu12-11.2.1.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 16 |
+
nvidia_cufft_cu12-11.2.1.3.dist-info/License.txt,sha256=rW9YU_ugyg0VnQ9Y1JrkmDDC-Mk_epJki5zpCttMbM0,59262
|
| 17 |
+
nvidia_cufft_cu12-11.2.1.3.dist-info/METADATA,sha256=e3c8JR1hTBAIlY96lfSibInmFGkkwNcYO6CExGuXQ6w,1502
|
| 18 |
+
nvidia_cufft_cu12-11.2.1.3.dist-info/RECORD,,
|
| 19 |
+
nvidia_cufft_cu12-11.2.1.3.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 20 |
+
nvidia_cufft_cu12-11.2.1.3.dist-info/WHEEL,sha256=XDTs3wIbcE-BcRO08VJlZpA6z9OaC1mOKPCGGGwuM2g,109
|
| 21 |
+
nvidia_cufft_cu12-11.2.1.3.dist-info/top_level.txt,sha256=fTkAtiFuL16nUrB9ytDDtpytz2t0B4NvYTnRzwAhO14,7
|
mplug_owl2/lib/python3.10/site-packages/nvidia_cufft_cu12-11.2.1.3.dist-info/REQUESTED
ADDED
|
File without changes
|
mplug_owl2/lib/python3.10/site-packages/nvidia_cufft_cu12-11.2.1.3.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.42.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-manylinux2014_x86_64
|
| 5 |
+
|
mplug_owl2/lib/python3.10/site-packages/nvidia_cufft_cu12-11.2.1.3.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
nvidia
|
mplug_owl2/lib/python3.10/site-packages/psutil/__init__.py
ADDED
|
@@ -0,0 +1,2486 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
|
| 3 |
+
# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
|
| 4 |
+
# Use of this source code is governed by a BSD-style license that can be
|
| 5 |
+
# found in the LICENSE file.
|
| 6 |
+
|
| 7 |
+
"""psutil is a cross-platform library for retrieving information on
|
| 8 |
+
running processes and system utilization (CPU, memory, disks, network,
|
| 9 |
+
sensors) in Python. Supported platforms:
|
| 10 |
+
|
| 11 |
+
- Linux
|
| 12 |
+
- Windows
|
| 13 |
+
- macOS
|
| 14 |
+
- FreeBSD
|
| 15 |
+
- OpenBSD
|
| 16 |
+
- NetBSD
|
| 17 |
+
- Sun Solaris
|
| 18 |
+
- AIX
|
| 19 |
+
|
| 20 |
+
Works with Python versions 2.7 and 3.6+.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
from __future__ import division
|
| 24 |
+
|
| 25 |
+
import collections
|
| 26 |
+
import contextlib
|
| 27 |
+
import datetime
|
| 28 |
+
import functools
|
| 29 |
+
import os
|
| 30 |
+
import signal
|
| 31 |
+
import subprocess
|
| 32 |
+
import sys
|
| 33 |
+
import threading
|
| 34 |
+
import time
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
import pwd
|
| 39 |
+
except ImportError:
|
| 40 |
+
pwd = None
|
| 41 |
+
|
| 42 |
+
from . import _common
|
| 43 |
+
from ._common import AIX
|
| 44 |
+
from ._common import BSD
|
| 45 |
+
from ._common import CONN_CLOSE
|
| 46 |
+
from ._common import CONN_CLOSE_WAIT
|
| 47 |
+
from ._common import CONN_CLOSING
|
| 48 |
+
from ._common import CONN_ESTABLISHED
|
| 49 |
+
from ._common import CONN_FIN_WAIT1
|
| 50 |
+
from ._common import CONN_FIN_WAIT2
|
| 51 |
+
from ._common import CONN_LAST_ACK
|
| 52 |
+
from ._common import CONN_LISTEN
|
| 53 |
+
from ._common import CONN_NONE
|
| 54 |
+
from ._common import CONN_SYN_RECV
|
| 55 |
+
from ._common import CONN_SYN_SENT
|
| 56 |
+
from ._common import CONN_TIME_WAIT
|
| 57 |
+
from ._common import FREEBSD # NOQA
|
| 58 |
+
from ._common import LINUX
|
| 59 |
+
from ._common import MACOS
|
| 60 |
+
from ._common import NETBSD # NOQA
|
| 61 |
+
from ._common import NIC_DUPLEX_FULL
|
| 62 |
+
from ._common import NIC_DUPLEX_HALF
|
| 63 |
+
from ._common import NIC_DUPLEX_UNKNOWN
|
| 64 |
+
from ._common import OPENBSD # NOQA
|
| 65 |
+
from ._common import OSX # deprecated alias
|
| 66 |
+
from ._common import POSIX # NOQA
|
| 67 |
+
from ._common import POWER_TIME_UNKNOWN
|
| 68 |
+
from ._common import POWER_TIME_UNLIMITED
|
| 69 |
+
from ._common import STATUS_DEAD
|
| 70 |
+
from ._common import STATUS_DISK_SLEEP
|
| 71 |
+
from ._common import STATUS_IDLE
|
| 72 |
+
from ._common import STATUS_LOCKED
|
| 73 |
+
from ._common import STATUS_PARKED
|
| 74 |
+
from ._common import STATUS_RUNNING
|
| 75 |
+
from ._common import STATUS_SLEEPING
|
| 76 |
+
from ._common import STATUS_STOPPED
|
| 77 |
+
from ._common import STATUS_TRACING_STOP
|
| 78 |
+
from ._common import STATUS_WAITING
|
| 79 |
+
from ._common import STATUS_WAKING
|
| 80 |
+
from ._common import STATUS_ZOMBIE
|
| 81 |
+
from ._common import SUNOS
|
| 82 |
+
from ._common import WINDOWS
|
| 83 |
+
from ._common import AccessDenied
|
| 84 |
+
from ._common import Error
|
| 85 |
+
from ._common import NoSuchProcess
|
| 86 |
+
from ._common import TimeoutExpired
|
| 87 |
+
from ._common import ZombieProcess
|
| 88 |
+
from ._common import debug
|
| 89 |
+
from ._common import memoize_when_activated
|
| 90 |
+
from ._common import wrap_numbers as _wrap_numbers
|
| 91 |
+
from ._compat import PY3 as _PY3
|
| 92 |
+
from ._compat import PermissionError
|
| 93 |
+
from ._compat import ProcessLookupError
|
| 94 |
+
from ._compat import SubprocessTimeoutExpired as _SubprocessTimeoutExpired
|
| 95 |
+
from ._compat import long
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
if LINUX:
|
| 99 |
+
# This is public API and it will be retrieved from _pslinux.py
|
| 100 |
+
# via sys.modules.
|
| 101 |
+
PROCFS_PATH = "/proc"
|
| 102 |
+
|
| 103 |
+
from . import _pslinux as _psplatform
|
| 104 |
+
from ._pslinux import IOPRIO_CLASS_BE # NOQA
|
| 105 |
+
from ._pslinux import IOPRIO_CLASS_IDLE # NOQA
|
| 106 |
+
from ._pslinux import IOPRIO_CLASS_NONE # NOQA
|
| 107 |
+
from ._pslinux import IOPRIO_CLASS_RT # NOQA
|
| 108 |
+
|
| 109 |
+
elif WINDOWS:
|
| 110 |
+
from . import _pswindows as _psplatform
|
| 111 |
+
from ._psutil_windows import ABOVE_NORMAL_PRIORITY_CLASS # NOQA
|
| 112 |
+
from ._psutil_windows import BELOW_NORMAL_PRIORITY_CLASS # NOQA
|
| 113 |
+
from ._psutil_windows import HIGH_PRIORITY_CLASS # NOQA
|
| 114 |
+
from ._psutil_windows import IDLE_PRIORITY_CLASS # NOQA
|
| 115 |
+
from ._psutil_windows import NORMAL_PRIORITY_CLASS # NOQA
|
| 116 |
+
from ._psutil_windows import REALTIME_PRIORITY_CLASS # NOQA
|
| 117 |
+
from ._pswindows import CONN_DELETE_TCB # NOQA
|
| 118 |
+
from ._pswindows import IOPRIO_HIGH # NOQA
|
| 119 |
+
from ._pswindows import IOPRIO_LOW # NOQA
|
| 120 |
+
from ._pswindows import IOPRIO_NORMAL # NOQA
|
| 121 |
+
from ._pswindows import IOPRIO_VERYLOW # NOQA
|
| 122 |
+
|
| 123 |
+
elif MACOS:
|
| 124 |
+
from . import _psosx as _psplatform
|
| 125 |
+
|
| 126 |
+
elif BSD:
|
| 127 |
+
from . import _psbsd as _psplatform
|
| 128 |
+
|
| 129 |
+
elif SUNOS:
|
| 130 |
+
from . import _pssunos as _psplatform
|
| 131 |
+
from ._pssunos import CONN_BOUND # NOQA
|
| 132 |
+
from ._pssunos import CONN_IDLE # NOQA
|
| 133 |
+
|
| 134 |
+
# This is public writable API which is read from _pslinux.py and
|
| 135 |
+
# _pssunos.py via sys.modules.
|
| 136 |
+
PROCFS_PATH = "/proc"
|
| 137 |
+
|
| 138 |
+
elif AIX:
|
| 139 |
+
from . import _psaix as _psplatform
|
| 140 |
+
|
| 141 |
+
# This is public API and it will be retrieved from _pslinux.py
|
| 142 |
+
# via sys.modules.
|
| 143 |
+
PROCFS_PATH = "/proc"
|
| 144 |
+
|
| 145 |
+
else: # pragma: no cover
|
| 146 |
+
raise NotImplementedError('platform %s is not supported' % sys.platform)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# fmt: off
|
| 150 |
+
__all__ = [
|
| 151 |
+
# exceptions
|
| 152 |
+
"Error", "NoSuchProcess", "ZombieProcess", "AccessDenied",
|
| 153 |
+
"TimeoutExpired",
|
| 154 |
+
|
| 155 |
+
# constants
|
| 156 |
+
"version_info", "__version__",
|
| 157 |
+
|
| 158 |
+
"STATUS_RUNNING", "STATUS_IDLE", "STATUS_SLEEPING", "STATUS_DISK_SLEEP",
|
| 159 |
+
"STATUS_STOPPED", "STATUS_TRACING_STOP", "STATUS_ZOMBIE", "STATUS_DEAD",
|
| 160 |
+
"STATUS_WAKING", "STATUS_LOCKED", "STATUS_WAITING", "STATUS_LOCKED",
|
| 161 |
+
"STATUS_PARKED",
|
| 162 |
+
|
| 163 |
+
"CONN_ESTABLISHED", "CONN_SYN_SENT", "CONN_SYN_RECV", "CONN_FIN_WAIT1",
|
| 164 |
+
"CONN_FIN_WAIT2", "CONN_TIME_WAIT", "CONN_CLOSE", "CONN_CLOSE_WAIT",
|
| 165 |
+
"CONN_LAST_ACK", "CONN_LISTEN", "CONN_CLOSING", "CONN_NONE",
|
| 166 |
+
# "CONN_IDLE", "CONN_BOUND",
|
| 167 |
+
|
| 168 |
+
"AF_LINK",
|
| 169 |
+
|
| 170 |
+
"NIC_DUPLEX_FULL", "NIC_DUPLEX_HALF", "NIC_DUPLEX_UNKNOWN",
|
| 171 |
+
|
| 172 |
+
"POWER_TIME_UNKNOWN", "POWER_TIME_UNLIMITED",
|
| 173 |
+
|
| 174 |
+
"BSD", "FREEBSD", "LINUX", "NETBSD", "OPENBSD", "MACOS", "OSX", "POSIX",
|
| 175 |
+
"SUNOS", "WINDOWS", "AIX",
|
| 176 |
+
|
| 177 |
+
# "RLIM_INFINITY", "RLIMIT_AS", "RLIMIT_CORE", "RLIMIT_CPU", "RLIMIT_DATA",
|
| 178 |
+
# "RLIMIT_FSIZE", "RLIMIT_LOCKS", "RLIMIT_MEMLOCK", "RLIMIT_NOFILE",
|
| 179 |
+
# "RLIMIT_NPROC", "RLIMIT_RSS", "RLIMIT_STACK", "RLIMIT_MSGQUEUE",
|
| 180 |
+
# "RLIMIT_NICE", "RLIMIT_RTPRIO", "RLIMIT_RTTIME", "RLIMIT_SIGPENDING",
|
| 181 |
+
|
| 182 |
+
# classes
|
| 183 |
+
"Process", "Popen",
|
| 184 |
+
|
| 185 |
+
# functions
|
| 186 |
+
"pid_exists", "pids", "process_iter", "wait_procs", # proc
|
| 187 |
+
"virtual_memory", "swap_memory", # memory
|
| 188 |
+
"cpu_times", "cpu_percent", "cpu_times_percent", "cpu_count", # cpu
|
| 189 |
+
"cpu_stats", # "cpu_freq", "getloadavg"
|
| 190 |
+
"net_io_counters", "net_connections", "net_if_addrs", # network
|
| 191 |
+
"net_if_stats",
|
| 192 |
+
"disk_io_counters", "disk_partitions", "disk_usage", # disk
|
| 193 |
+
# "sensors_temperatures", "sensors_battery", "sensors_fans" # sensors
|
| 194 |
+
"users", "boot_time", # others
|
| 195 |
+
]
|
| 196 |
+
# fmt: on
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
__all__.extend(_psplatform.__extra__all__)
|
| 200 |
+
|
| 201 |
+
# Linux, FreeBSD
|
| 202 |
+
if hasattr(_psplatform.Process, "rlimit"):
|
| 203 |
+
# Populate global namespace with RLIM* constants.
|
| 204 |
+
from . import _psutil_posix
|
| 205 |
+
|
| 206 |
+
_globals = globals()
|
| 207 |
+
_name = None
|
| 208 |
+
for _name in dir(_psutil_posix):
|
| 209 |
+
if _name.startswith('RLIM') and _name.isupper():
|
| 210 |
+
_globals[_name] = getattr(_psutil_posix, _name)
|
| 211 |
+
__all__.append(_name)
|
| 212 |
+
del _globals, _name
|
| 213 |
+
|
| 214 |
+
AF_LINK = _psplatform.AF_LINK
|
| 215 |
+
|
| 216 |
+
__author__ = "Giampaolo Rodola'"
|
| 217 |
+
__version__ = "6.1.1"
|
| 218 |
+
version_info = tuple([int(num) for num in __version__.split('.')])
|
| 219 |
+
|
| 220 |
+
_timer = getattr(time, 'monotonic', time.time)
|
| 221 |
+
_TOTAL_PHYMEM = None
|
| 222 |
+
_LOWEST_PID = None
|
| 223 |
+
_SENTINEL = object()
|
| 224 |
+
|
| 225 |
+
# Sanity check in case the user messed up with psutil installation
|
| 226 |
+
# or did something weird with sys.path. In this case we might end
|
| 227 |
+
# up importing a python module using a C extension module which
|
| 228 |
+
# was compiled for a different version of psutil.
|
| 229 |
+
# We want to prevent that by failing sooner rather than later.
|
| 230 |
+
# See: https://github.com/giampaolo/psutil/issues/564
|
| 231 |
+
if int(__version__.replace('.', '')) != getattr(
|
| 232 |
+
_psplatform.cext, 'version', None
|
| 233 |
+
):
|
| 234 |
+
msg = "version conflict: %r C extension " % _psplatform.cext.__file__
|
| 235 |
+
msg += "module was built for another version of psutil"
|
| 236 |
+
if hasattr(_psplatform.cext, 'version'):
|
| 237 |
+
msg += " (%s instead of %s)" % (
|
| 238 |
+
'.'.join([x for x in str(_psplatform.cext.version)]),
|
| 239 |
+
__version__,
|
| 240 |
+
)
|
| 241 |
+
else:
|
| 242 |
+
msg += " (different than %s)" % __version__
|
| 243 |
+
msg += "; you may try to 'pip uninstall psutil', manually remove %s" % (
|
| 244 |
+
getattr(
|
| 245 |
+
_psplatform.cext,
|
| 246 |
+
"__file__",
|
| 247 |
+
"the existing psutil install directory",
|
| 248 |
+
)
|
| 249 |
+
)
|
| 250 |
+
msg += " or clean the virtual env somehow, then reinstall"
|
| 251 |
+
raise ImportError(msg)
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
# =====================================================================
|
| 255 |
+
# --- Utils
|
| 256 |
+
# =====================================================================
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
if hasattr(_psplatform, 'ppid_map'):
|
| 260 |
+
# Faster version (Windows and Linux).
|
| 261 |
+
_ppid_map = _psplatform.ppid_map
|
| 262 |
+
else: # pragma: no cover
|
| 263 |
+
|
| 264 |
+
def _ppid_map():
|
| 265 |
+
"""Return a {pid: ppid, ...} dict for all running processes in
|
| 266 |
+
one shot. Used to speed up Process.children().
|
| 267 |
+
"""
|
| 268 |
+
ret = {}
|
| 269 |
+
for pid in pids():
|
| 270 |
+
try:
|
| 271 |
+
ret[pid] = _psplatform.Process(pid).ppid()
|
| 272 |
+
except (NoSuchProcess, ZombieProcess):
|
| 273 |
+
pass
|
| 274 |
+
return ret
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def _pprint_secs(secs):
|
| 278 |
+
"""Format seconds in a human readable form."""
|
| 279 |
+
now = time.time()
|
| 280 |
+
secs_ago = int(now - secs)
|
| 281 |
+
fmt = "%H:%M:%S" if secs_ago < 60 * 60 * 24 else "%Y-%m-%d %H:%M:%S"
|
| 282 |
+
return datetime.datetime.fromtimestamp(secs).strftime(fmt)
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
# =====================================================================
|
| 286 |
+
# --- Process class
|
| 287 |
+
# =====================================================================
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
class Process(object): # noqa: UP004
|
| 291 |
+
"""Represents an OS process with the given PID.
|
| 292 |
+
If PID is omitted current process PID (os.getpid()) is used.
|
| 293 |
+
Raise NoSuchProcess if PID does not exist.
|
| 294 |
+
|
| 295 |
+
Note that most of the methods of this class do not make sure that
|
| 296 |
+
the PID of the process being queried has been reused. That means
|
| 297 |
+
that you may end up retrieving information for another process.
|
| 298 |
+
|
| 299 |
+
The only exceptions for which process identity is pre-emptively
|
| 300 |
+
checked and guaranteed are:
|
| 301 |
+
|
| 302 |
+
- parent()
|
| 303 |
+
- children()
|
| 304 |
+
- nice() (set)
|
| 305 |
+
- ionice() (set)
|
| 306 |
+
- rlimit() (set)
|
| 307 |
+
- cpu_affinity (set)
|
| 308 |
+
- suspend()
|
| 309 |
+
- resume()
|
| 310 |
+
- send_signal()
|
| 311 |
+
- terminate()
|
| 312 |
+
- kill()
|
| 313 |
+
|
| 314 |
+
To prevent this problem for all other methods you can use
|
| 315 |
+
is_running() before querying the process.
|
| 316 |
+
"""
|
| 317 |
+
|
| 318 |
+
def __init__(self, pid=None):
|
| 319 |
+
self._init(pid)
|
| 320 |
+
|
| 321 |
+
def _init(self, pid, _ignore_nsp=False):
|
| 322 |
+
if pid is None:
|
| 323 |
+
pid = os.getpid()
|
| 324 |
+
else:
|
| 325 |
+
if not _PY3 and not isinstance(pid, (int, long)):
|
| 326 |
+
msg = "pid must be an integer (got %r)" % pid
|
| 327 |
+
raise TypeError(msg)
|
| 328 |
+
if pid < 0:
|
| 329 |
+
msg = "pid must be a positive integer (got %s)" % pid
|
| 330 |
+
raise ValueError(msg)
|
| 331 |
+
try:
|
| 332 |
+
_psplatform.cext.check_pid_range(pid)
|
| 333 |
+
except OverflowError:
|
| 334 |
+
msg = "process PID out of range (got %s)" % pid
|
| 335 |
+
raise NoSuchProcess(pid, msg=msg)
|
| 336 |
+
|
| 337 |
+
self._pid = pid
|
| 338 |
+
self._name = None
|
| 339 |
+
self._exe = None
|
| 340 |
+
self._create_time = None
|
| 341 |
+
self._gone = False
|
| 342 |
+
self._pid_reused = False
|
| 343 |
+
self._hash = None
|
| 344 |
+
self._lock = threading.RLock()
|
| 345 |
+
# used for caching on Windows only (on POSIX ppid may change)
|
| 346 |
+
self._ppid = None
|
| 347 |
+
# platform-specific modules define an _psplatform.Process
|
| 348 |
+
# implementation class
|
| 349 |
+
self._proc = _psplatform.Process(pid)
|
| 350 |
+
self._last_sys_cpu_times = None
|
| 351 |
+
self._last_proc_cpu_times = None
|
| 352 |
+
self._exitcode = _SENTINEL
|
| 353 |
+
self._ident = (self.pid, None)
|
| 354 |
+
try:
|
| 355 |
+
self._ident = self._get_ident()
|
| 356 |
+
except AccessDenied:
|
| 357 |
+
# This should happen on Windows only, since we use the fast
|
| 358 |
+
# create time method. AFAIK, on all other platforms we are
|
| 359 |
+
# able to get create time for all PIDs.
|
| 360 |
+
pass
|
| 361 |
+
except ZombieProcess:
|
| 362 |
+
# Zombies can still be queried by this class (although
|
| 363 |
+
# not always) and pids() return them so just go on.
|
| 364 |
+
pass
|
| 365 |
+
except NoSuchProcess:
|
| 366 |
+
if not _ignore_nsp:
|
| 367 |
+
msg = "process PID not found"
|
| 368 |
+
raise NoSuchProcess(pid, msg=msg)
|
| 369 |
+
else:
|
| 370 |
+
self._gone = True
|
| 371 |
+
|
| 372 |
+
def _get_ident(self):
|
| 373 |
+
"""Return a (pid, uid) tuple which is supposed to identify a
|
| 374 |
+
Process instance univocally over time. The PID alone is not
|
| 375 |
+
enough, as it can be assigned to a new process after this one
|
| 376 |
+
terminates, so we add process creation time to the mix. We need
|
| 377 |
+
this in order to prevent killing the wrong process later on.
|
| 378 |
+
This is also known as PID reuse or PID recycling problem.
|
| 379 |
+
|
| 380 |
+
The reliability of this strategy mostly depends on
|
| 381 |
+
create_time() precision, which is 0.01 secs on Linux. The
|
| 382 |
+
assumption is that, after a process terminates, the kernel
|
| 383 |
+
won't reuse the same PID after such a short period of time
|
| 384 |
+
(0.01 secs). Technically this is inherently racy, but
|
| 385 |
+
practically it should be good enough.
|
| 386 |
+
"""
|
| 387 |
+
if WINDOWS:
|
| 388 |
+
# Use create_time() fast method in order to speedup
|
| 389 |
+
# `process_iter()`. This means we'll get AccessDenied for
|
| 390 |
+
# most ADMIN processes, but that's fine since it means
|
| 391 |
+
# we'll also get AccessDenied on kill().
|
| 392 |
+
# https://github.com/giampaolo/psutil/issues/2366#issuecomment-2381646555
|
| 393 |
+
self._create_time = self._proc.create_time(fast_only=True)
|
| 394 |
+
return (self.pid, self._create_time)
|
| 395 |
+
else:
|
| 396 |
+
return (self.pid, self.create_time())
|
| 397 |
+
|
| 398 |
+
def __str__(self):
|
| 399 |
+
info = collections.OrderedDict()
|
| 400 |
+
info["pid"] = self.pid
|
| 401 |
+
if self._name:
|
| 402 |
+
info['name'] = self._name
|
| 403 |
+
with self.oneshot():
|
| 404 |
+
if self._pid_reused:
|
| 405 |
+
info["status"] = "terminated + PID reused"
|
| 406 |
+
else:
|
| 407 |
+
try:
|
| 408 |
+
info["name"] = self.name()
|
| 409 |
+
info["status"] = self.status()
|
| 410 |
+
except ZombieProcess:
|
| 411 |
+
info["status"] = "zombie"
|
| 412 |
+
except NoSuchProcess:
|
| 413 |
+
info["status"] = "terminated"
|
| 414 |
+
except AccessDenied:
|
| 415 |
+
pass
|
| 416 |
+
|
| 417 |
+
if self._exitcode not in {_SENTINEL, None}:
|
| 418 |
+
info["exitcode"] = self._exitcode
|
| 419 |
+
if self._create_time is not None:
|
| 420 |
+
info['started'] = _pprint_secs(self._create_time)
|
| 421 |
+
|
| 422 |
+
return "%s.%s(%s)" % (
|
| 423 |
+
self.__class__.__module__,
|
| 424 |
+
self.__class__.__name__,
|
| 425 |
+
", ".join(["%s=%r" % (k, v) for k, v in info.items()]),
|
| 426 |
+
)
|
| 427 |
+
|
| 428 |
+
__repr__ = __str__
|
| 429 |
+
|
| 430 |
+
def __eq__(self, other):
|
| 431 |
+
# Test for equality with another Process object based
|
| 432 |
+
# on PID and creation time.
|
| 433 |
+
if not isinstance(other, Process):
|
| 434 |
+
return NotImplemented
|
| 435 |
+
if OPENBSD or NETBSD: # pragma: no cover
|
| 436 |
+
# Zombie processes on Open/NetBSD have a creation time of
|
| 437 |
+
# 0.0. This covers the case when a process started normally
|
| 438 |
+
# (so it has a ctime), then it turned into a zombie. It's
|
| 439 |
+
# important to do this because is_running() depends on
|
| 440 |
+
# __eq__.
|
| 441 |
+
pid1, ident1 = self._ident
|
| 442 |
+
pid2, ident2 = other._ident
|
| 443 |
+
if pid1 == pid2:
|
| 444 |
+
if ident1 and not ident2:
|
| 445 |
+
try:
|
| 446 |
+
return self.status() == STATUS_ZOMBIE
|
| 447 |
+
except Error:
|
| 448 |
+
pass
|
| 449 |
+
return self._ident == other._ident
|
| 450 |
+
|
| 451 |
+
def __ne__(self, other):
|
| 452 |
+
return not self == other
|
| 453 |
+
|
| 454 |
+
def __hash__(self):
|
| 455 |
+
if self._hash is None:
|
| 456 |
+
self._hash = hash(self._ident)
|
| 457 |
+
return self._hash
|
| 458 |
+
|
| 459 |
+
def _raise_if_pid_reused(self):
|
| 460 |
+
"""Raises NoSuchProcess in case process PID has been reused."""
|
| 461 |
+
if self._pid_reused or (not self.is_running() and self._pid_reused):
|
| 462 |
+
# We may directly raise NSP in here already if PID is just
|
| 463 |
+
# not running, but I prefer NSP to be raised naturally by
|
| 464 |
+
# the actual Process API call. This way unit tests will tell
|
| 465 |
+
# us if the API is broken (aka don't raise NSP when it
|
| 466 |
+
# should). We also remain consistent with all other "get"
|
| 467 |
+
# APIs which don't use _raise_if_pid_reused().
|
| 468 |
+
msg = "process no longer exists and its PID has been reused"
|
| 469 |
+
raise NoSuchProcess(self.pid, self._name, msg=msg)
|
| 470 |
+
|
| 471 |
+
@property
|
| 472 |
+
def pid(self):
|
| 473 |
+
"""The process PID."""
|
| 474 |
+
return self._pid
|
| 475 |
+
|
| 476 |
+
# --- utility methods
|
| 477 |
+
|
| 478 |
+
@contextlib.contextmanager
|
| 479 |
+
def oneshot(self):
|
| 480 |
+
"""Utility context manager which considerably speeds up the
|
| 481 |
+
retrieval of multiple process information at the same time.
|
| 482 |
+
|
| 483 |
+
Internally different process info (e.g. name, ppid, uids,
|
| 484 |
+
gids, ...) may be fetched by using the same routine, but
|
| 485 |
+
only one information is returned and the others are discarded.
|
| 486 |
+
When using this context manager the internal routine is
|
| 487 |
+
executed once (in the example below on name()) and the
|
| 488 |
+
other info are cached.
|
| 489 |
+
|
| 490 |
+
The cache is cleared when exiting the context manager block.
|
| 491 |
+
The advice is to use this every time you retrieve more than
|
| 492 |
+
one information about the process. If you're lucky, you'll
|
| 493 |
+
get a hell of a speedup.
|
| 494 |
+
|
| 495 |
+
>>> import psutil
|
| 496 |
+
>>> p = psutil.Process()
|
| 497 |
+
>>> with p.oneshot():
|
| 498 |
+
... p.name() # collect multiple info
|
| 499 |
+
... p.cpu_times() # return cached value
|
| 500 |
+
... p.cpu_percent() # return cached value
|
| 501 |
+
... p.create_time() # return cached value
|
| 502 |
+
...
|
| 503 |
+
>>>
|
| 504 |
+
"""
|
| 505 |
+
with self._lock:
|
| 506 |
+
if hasattr(self, "_cache"):
|
| 507 |
+
# NOOP: this covers the use case where the user enters the
|
| 508 |
+
# context twice:
|
| 509 |
+
#
|
| 510 |
+
# >>> with p.oneshot():
|
| 511 |
+
# ... with p.oneshot():
|
| 512 |
+
# ...
|
| 513 |
+
#
|
| 514 |
+
# Also, since as_dict() internally uses oneshot()
|
| 515 |
+
# I expect that the code below will be a pretty common
|
| 516 |
+
# "mistake" that the user will make, so let's guard
|
| 517 |
+
# against that:
|
| 518 |
+
#
|
| 519 |
+
# >>> with p.oneshot():
|
| 520 |
+
# ... p.as_dict()
|
| 521 |
+
# ...
|
| 522 |
+
yield
|
| 523 |
+
else:
|
| 524 |
+
try:
|
| 525 |
+
# cached in case cpu_percent() is used
|
| 526 |
+
self.cpu_times.cache_activate(self)
|
| 527 |
+
# cached in case memory_percent() is used
|
| 528 |
+
self.memory_info.cache_activate(self)
|
| 529 |
+
# cached in case parent() is used
|
| 530 |
+
self.ppid.cache_activate(self)
|
| 531 |
+
# cached in case username() is used
|
| 532 |
+
if POSIX:
|
| 533 |
+
self.uids.cache_activate(self)
|
| 534 |
+
# specific implementation cache
|
| 535 |
+
self._proc.oneshot_enter()
|
| 536 |
+
yield
|
| 537 |
+
finally:
|
| 538 |
+
self.cpu_times.cache_deactivate(self)
|
| 539 |
+
self.memory_info.cache_deactivate(self)
|
| 540 |
+
self.ppid.cache_deactivate(self)
|
| 541 |
+
if POSIX:
|
| 542 |
+
self.uids.cache_deactivate(self)
|
| 543 |
+
self._proc.oneshot_exit()
|
| 544 |
+
|
| 545 |
+
def as_dict(self, attrs=None, ad_value=None):
|
| 546 |
+
"""Utility method returning process information as a
|
| 547 |
+
hashable dictionary.
|
| 548 |
+
If *attrs* is specified it must be a list of strings
|
| 549 |
+
reflecting available Process class' attribute names
|
| 550 |
+
(e.g. ['cpu_times', 'name']) else all public (read
|
| 551 |
+
only) attributes are assumed.
|
| 552 |
+
*ad_value* is the value which gets assigned in case
|
| 553 |
+
AccessDenied or ZombieProcess exception is raised when
|
| 554 |
+
retrieving that particular process information.
|
| 555 |
+
"""
|
| 556 |
+
valid_names = _as_dict_attrnames
|
| 557 |
+
if attrs is not None:
|
| 558 |
+
if not isinstance(attrs, (list, tuple, set, frozenset)):
|
| 559 |
+
msg = "invalid attrs type %s" % type(attrs)
|
| 560 |
+
raise TypeError(msg)
|
| 561 |
+
attrs = set(attrs)
|
| 562 |
+
invalid_names = attrs - valid_names
|
| 563 |
+
if invalid_names:
|
| 564 |
+
msg = "invalid attr name%s %s" % (
|
| 565 |
+
"s" if len(invalid_names) > 1 else "",
|
| 566 |
+
", ".join(map(repr, invalid_names)),
|
| 567 |
+
)
|
| 568 |
+
raise ValueError(msg)
|
| 569 |
+
|
| 570 |
+
retdict = {}
|
| 571 |
+
ls = attrs or valid_names
|
| 572 |
+
with self.oneshot():
|
| 573 |
+
for name in ls:
|
| 574 |
+
try:
|
| 575 |
+
if name == 'pid':
|
| 576 |
+
ret = self.pid
|
| 577 |
+
else:
|
| 578 |
+
meth = getattr(self, name)
|
| 579 |
+
ret = meth()
|
| 580 |
+
except (AccessDenied, ZombieProcess):
|
| 581 |
+
ret = ad_value
|
| 582 |
+
except NotImplementedError:
|
| 583 |
+
# in case of not implemented functionality (may happen
|
| 584 |
+
# on old or exotic systems) we want to crash only if
|
| 585 |
+
# the user explicitly asked for that particular attr
|
| 586 |
+
if attrs:
|
| 587 |
+
raise
|
| 588 |
+
continue
|
| 589 |
+
retdict[name] = ret
|
| 590 |
+
return retdict
|
| 591 |
+
|
| 592 |
+
def parent(self):
|
| 593 |
+
"""Return the parent process as a Process object pre-emptively
|
| 594 |
+
checking whether PID has been reused.
|
| 595 |
+
If no parent is known return None.
|
| 596 |
+
"""
|
| 597 |
+
lowest_pid = _LOWEST_PID if _LOWEST_PID is not None else pids()[0]
|
| 598 |
+
if self.pid == lowest_pid:
|
| 599 |
+
return None
|
| 600 |
+
ppid = self.ppid()
|
| 601 |
+
if ppid is not None:
|
| 602 |
+
ctime = self.create_time()
|
| 603 |
+
try:
|
| 604 |
+
parent = Process(ppid)
|
| 605 |
+
if parent.create_time() <= ctime:
|
| 606 |
+
return parent
|
| 607 |
+
# ...else ppid has been reused by another process
|
| 608 |
+
except NoSuchProcess:
|
| 609 |
+
pass
|
| 610 |
+
|
| 611 |
+
def parents(self):
|
| 612 |
+
"""Return the parents of this process as a list of Process
|
| 613 |
+
instances. If no parents are known return an empty list.
|
| 614 |
+
"""
|
| 615 |
+
parents = []
|
| 616 |
+
proc = self.parent()
|
| 617 |
+
while proc is not None:
|
| 618 |
+
parents.append(proc)
|
| 619 |
+
proc = proc.parent()
|
| 620 |
+
return parents
|
| 621 |
+
|
| 622 |
+
def is_running(self):
|
| 623 |
+
"""Return whether this process is running.
|
| 624 |
+
|
| 625 |
+
It also checks if PID has been reused by another process, in
|
| 626 |
+
which case it will remove the process from `process_iter()`
|
| 627 |
+
internal cache and return False.
|
| 628 |
+
"""
|
| 629 |
+
if self._gone or self._pid_reused:
|
| 630 |
+
return False
|
| 631 |
+
try:
|
| 632 |
+
# Checking if PID is alive is not enough as the PID might
|
| 633 |
+
# have been reused by another process. Process identity /
|
| 634 |
+
# uniqueness over time is guaranteed by (PID + creation
|
| 635 |
+
# time) and that is verified in __eq__.
|
| 636 |
+
self._pid_reused = self != Process(self.pid)
|
| 637 |
+
if self._pid_reused:
|
| 638 |
+
_pids_reused.add(self.pid)
|
| 639 |
+
raise NoSuchProcess(self.pid)
|
| 640 |
+
return True
|
| 641 |
+
except ZombieProcess:
|
| 642 |
+
# We should never get here as it's already handled in
|
| 643 |
+
# Process.__init__; here just for extra safety.
|
| 644 |
+
return True
|
| 645 |
+
except NoSuchProcess:
|
| 646 |
+
self._gone = True
|
| 647 |
+
return False
|
| 648 |
+
|
| 649 |
+
# --- actual API
|
| 650 |
+
|
| 651 |
+
@memoize_when_activated
|
| 652 |
+
def ppid(self):
|
| 653 |
+
"""The process parent PID.
|
| 654 |
+
On Windows the return value is cached after first call.
|
| 655 |
+
"""
|
| 656 |
+
# On POSIX we don't want to cache the ppid as it may unexpectedly
|
| 657 |
+
# change to 1 (init) in case this process turns into a zombie:
|
| 658 |
+
# https://github.com/giampaolo/psutil/issues/321
|
| 659 |
+
# http://stackoverflow.com/questions/356722/
|
| 660 |
+
|
| 661 |
+
# XXX should we check creation time here rather than in
|
| 662 |
+
# Process.parent()?
|
| 663 |
+
self._raise_if_pid_reused()
|
| 664 |
+
if POSIX:
|
| 665 |
+
return self._proc.ppid()
|
| 666 |
+
else: # pragma: no cover
|
| 667 |
+
self._ppid = self._ppid or self._proc.ppid()
|
| 668 |
+
return self._ppid
|
| 669 |
+
|
| 670 |
+
def name(self):
|
| 671 |
+
"""The process name. The return value is cached after first call."""
|
| 672 |
+
# Process name is only cached on Windows as on POSIX it may
|
| 673 |
+
# change, see:
|
| 674 |
+
# https://github.com/giampaolo/psutil/issues/692
|
| 675 |
+
if WINDOWS and self._name is not None:
|
| 676 |
+
return self._name
|
| 677 |
+
name = self._proc.name()
|
| 678 |
+
if POSIX and len(name) >= 15:
|
| 679 |
+
# On UNIX the name gets truncated to the first 15 characters.
|
| 680 |
+
# If it matches the first part of the cmdline we return that
|
| 681 |
+
# one instead because it's usually more explicative.
|
| 682 |
+
# Examples are "gnome-keyring-d" vs. "gnome-keyring-daemon".
|
| 683 |
+
try:
|
| 684 |
+
cmdline = self.cmdline()
|
| 685 |
+
except (AccessDenied, ZombieProcess):
|
| 686 |
+
# Just pass and return the truncated name: it's better
|
| 687 |
+
# than nothing. Note: there are actual cases where a
|
| 688 |
+
# zombie process can return a name() but not a
|
| 689 |
+
# cmdline(), see:
|
| 690 |
+
# https://github.com/giampaolo/psutil/issues/2239
|
| 691 |
+
pass
|
| 692 |
+
else:
|
| 693 |
+
if cmdline:
|
| 694 |
+
extended_name = os.path.basename(cmdline[0])
|
| 695 |
+
if extended_name.startswith(name):
|
| 696 |
+
name = extended_name
|
| 697 |
+
self._name = name
|
| 698 |
+
self._proc._name = name
|
| 699 |
+
return name
|
| 700 |
+
|
| 701 |
+
def exe(self):
|
| 702 |
+
"""The process executable as an absolute path.
|
| 703 |
+
May also be an empty string.
|
| 704 |
+
The return value is cached after first call.
|
| 705 |
+
"""
|
| 706 |
+
|
| 707 |
+
def guess_it(fallback):
|
| 708 |
+
# try to guess exe from cmdline[0] in absence of a native
|
| 709 |
+
# exe representation
|
| 710 |
+
cmdline = self.cmdline()
|
| 711 |
+
if cmdline and hasattr(os, 'access') and hasattr(os, 'X_OK'):
|
| 712 |
+
exe = cmdline[0] # the possible exe
|
| 713 |
+
# Attempt to guess only in case of an absolute path.
|
| 714 |
+
# It is not safe otherwise as the process might have
|
| 715 |
+
# changed cwd.
|
| 716 |
+
if (
|
| 717 |
+
os.path.isabs(exe)
|
| 718 |
+
and os.path.isfile(exe)
|
| 719 |
+
and os.access(exe, os.X_OK)
|
| 720 |
+
):
|
| 721 |
+
return exe
|
| 722 |
+
if isinstance(fallback, AccessDenied):
|
| 723 |
+
raise fallback
|
| 724 |
+
return fallback
|
| 725 |
+
|
| 726 |
+
if self._exe is None:
|
| 727 |
+
try:
|
| 728 |
+
exe = self._proc.exe()
|
| 729 |
+
except AccessDenied as err:
|
| 730 |
+
return guess_it(fallback=err)
|
| 731 |
+
else:
|
| 732 |
+
if not exe:
|
| 733 |
+
# underlying implementation can legitimately return an
|
| 734 |
+
# empty string; if that's the case we don't want to
|
| 735 |
+
# raise AD while guessing from the cmdline
|
| 736 |
+
try:
|
| 737 |
+
exe = guess_it(fallback=exe)
|
| 738 |
+
except AccessDenied:
|
| 739 |
+
pass
|
| 740 |
+
self._exe = exe
|
| 741 |
+
return self._exe
|
| 742 |
+
|
| 743 |
+
def cmdline(self):
|
| 744 |
+
"""The command line this process has been called with."""
|
| 745 |
+
return self._proc.cmdline()
|
| 746 |
+
|
| 747 |
+
def status(self):
|
| 748 |
+
"""The process current status as a STATUS_* constant."""
|
| 749 |
+
try:
|
| 750 |
+
return self._proc.status()
|
| 751 |
+
except ZombieProcess:
|
| 752 |
+
return STATUS_ZOMBIE
|
| 753 |
+
|
| 754 |
+
def username(self):
|
| 755 |
+
"""The name of the user that owns the process.
|
| 756 |
+
On UNIX this is calculated by using *real* process uid.
|
| 757 |
+
"""
|
| 758 |
+
if POSIX:
|
| 759 |
+
if pwd is None:
|
| 760 |
+
# might happen if python was installed from sources
|
| 761 |
+
msg = "requires pwd module shipped with standard python"
|
| 762 |
+
raise ImportError(msg)
|
| 763 |
+
real_uid = self.uids().real
|
| 764 |
+
try:
|
| 765 |
+
return pwd.getpwuid(real_uid).pw_name
|
| 766 |
+
except KeyError:
|
| 767 |
+
# the uid can't be resolved by the system
|
| 768 |
+
return str(real_uid)
|
| 769 |
+
else:
|
| 770 |
+
return self._proc.username()
|
| 771 |
+
|
| 772 |
+
def create_time(self):
|
| 773 |
+
"""The process creation time as a floating point number
|
| 774 |
+
expressed in seconds since the epoch.
|
| 775 |
+
The return value is cached after first call.
|
| 776 |
+
"""
|
| 777 |
+
if self._create_time is None:
|
| 778 |
+
self._create_time = self._proc.create_time()
|
| 779 |
+
return self._create_time
|
| 780 |
+
|
| 781 |
+
def cwd(self):
|
| 782 |
+
"""Process current working directory as an absolute path."""
|
| 783 |
+
return self._proc.cwd()
|
| 784 |
+
|
| 785 |
+
def nice(self, value=None):
|
| 786 |
+
"""Get or set process niceness (priority)."""
|
| 787 |
+
if value is None:
|
| 788 |
+
return self._proc.nice_get()
|
| 789 |
+
else:
|
| 790 |
+
self._raise_if_pid_reused()
|
| 791 |
+
self._proc.nice_set(value)
|
| 792 |
+
|
| 793 |
+
if POSIX:
|
| 794 |
+
|
| 795 |
+
@memoize_when_activated
|
| 796 |
+
def uids(self):
|
| 797 |
+
"""Return process UIDs as a (real, effective, saved)
|
| 798 |
+
namedtuple.
|
| 799 |
+
"""
|
| 800 |
+
return self._proc.uids()
|
| 801 |
+
|
| 802 |
+
def gids(self):
|
| 803 |
+
"""Return process GIDs as a (real, effective, saved)
|
| 804 |
+
namedtuple.
|
| 805 |
+
"""
|
| 806 |
+
return self._proc.gids()
|
| 807 |
+
|
| 808 |
+
def terminal(self):
|
| 809 |
+
"""The terminal associated with this process, if any,
|
| 810 |
+
else None.
|
| 811 |
+
"""
|
| 812 |
+
return self._proc.terminal()
|
| 813 |
+
|
| 814 |
+
def num_fds(self):
|
| 815 |
+
"""Return the number of file descriptors opened by this
|
| 816 |
+
process (POSIX only).
|
| 817 |
+
"""
|
| 818 |
+
return self._proc.num_fds()
|
| 819 |
+
|
| 820 |
+
# Linux, BSD, AIX and Windows only
|
| 821 |
+
if hasattr(_psplatform.Process, "io_counters"):
|
| 822 |
+
|
| 823 |
+
def io_counters(self):
|
| 824 |
+
"""Return process I/O statistics as a
|
| 825 |
+
(read_count, write_count, read_bytes, write_bytes)
|
| 826 |
+
namedtuple.
|
| 827 |
+
Those are the number of read/write calls performed and the
|
| 828 |
+
amount of bytes read and written by the process.
|
| 829 |
+
"""
|
| 830 |
+
return self._proc.io_counters()
|
| 831 |
+
|
| 832 |
+
# Linux and Windows
|
| 833 |
+
if hasattr(_psplatform.Process, "ionice_get"):
|
| 834 |
+
|
| 835 |
+
def ionice(self, ioclass=None, value=None):
|
| 836 |
+
"""Get or set process I/O niceness (priority).
|
| 837 |
+
|
| 838 |
+
On Linux *ioclass* is one of the IOPRIO_CLASS_* constants.
|
| 839 |
+
*value* is a number which goes from 0 to 7. The higher the
|
| 840 |
+
value, the lower the I/O priority of the process.
|
| 841 |
+
|
| 842 |
+
On Windows only *ioclass* is used and it can be set to 2
|
| 843 |
+
(normal), 1 (low) or 0 (very low).
|
| 844 |
+
|
| 845 |
+
Available on Linux and Windows > Vista only.
|
| 846 |
+
"""
|
| 847 |
+
if ioclass is None:
|
| 848 |
+
if value is not None:
|
| 849 |
+
msg = "'ioclass' argument must be specified"
|
| 850 |
+
raise ValueError(msg)
|
| 851 |
+
return self._proc.ionice_get()
|
| 852 |
+
else:
|
| 853 |
+
self._raise_if_pid_reused()
|
| 854 |
+
return self._proc.ionice_set(ioclass, value)
|
| 855 |
+
|
| 856 |
+
# Linux / FreeBSD only
|
| 857 |
+
if hasattr(_psplatform.Process, "rlimit"):
|
| 858 |
+
|
| 859 |
+
def rlimit(self, resource, limits=None):
|
| 860 |
+
"""Get or set process resource limits as a (soft, hard)
|
| 861 |
+
tuple.
|
| 862 |
+
|
| 863 |
+
*resource* is one of the RLIMIT_* constants.
|
| 864 |
+
*limits* is supposed to be a (soft, hard) tuple.
|
| 865 |
+
|
| 866 |
+
See "man prlimit" for further info.
|
| 867 |
+
Available on Linux and FreeBSD only.
|
| 868 |
+
"""
|
| 869 |
+
if limits is not None:
|
| 870 |
+
self._raise_if_pid_reused()
|
| 871 |
+
return self._proc.rlimit(resource, limits)
|
| 872 |
+
|
| 873 |
+
# Windows, Linux and FreeBSD only
|
| 874 |
+
if hasattr(_psplatform.Process, "cpu_affinity_get"):
|
| 875 |
+
|
| 876 |
+
def cpu_affinity(self, cpus=None):
|
| 877 |
+
"""Get or set process CPU affinity.
|
| 878 |
+
If specified, *cpus* must be a list of CPUs for which you
|
| 879 |
+
want to set the affinity (e.g. [0, 1]).
|
| 880 |
+
If an empty list is passed, all egible CPUs are assumed
|
| 881 |
+
(and set).
|
| 882 |
+
(Windows, Linux and BSD only).
|
| 883 |
+
"""
|
| 884 |
+
if cpus is None:
|
| 885 |
+
return sorted(set(self._proc.cpu_affinity_get()))
|
| 886 |
+
else:
|
| 887 |
+
self._raise_if_pid_reused()
|
| 888 |
+
if not cpus:
|
| 889 |
+
if hasattr(self._proc, "_get_eligible_cpus"):
|
| 890 |
+
cpus = self._proc._get_eligible_cpus()
|
| 891 |
+
else:
|
| 892 |
+
cpus = tuple(range(len(cpu_times(percpu=True))))
|
| 893 |
+
self._proc.cpu_affinity_set(list(set(cpus)))
|
| 894 |
+
|
| 895 |
+
# Linux, FreeBSD, SunOS
|
| 896 |
+
if hasattr(_psplatform.Process, "cpu_num"):
|
| 897 |
+
|
| 898 |
+
def cpu_num(self):
|
| 899 |
+
"""Return what CPU this process is currently running on.
|
| 900 |
+
The returned number should be <= psutil.cpu_count()
|
| 901 |
+
and <= len(psutil.cpu_percent(percpu=True)).
|
| 902 |
+
It may be used in conjunction with
|
| 903 |
+
psutil.cpu_percent(percpu=True) to observe the system
|
| 904 |
+
workload distributed across CPUs.
|
| 905 |
+
"""
|
| 906 |
+
return self._proc.cpu_num()
|
| 907 |
+
|
| 908 |
+
# All platforms has it, but maybe not in the future.
|
| 909 |
+
if hasattr(_psplatform.Process, "environ"):
|
| 910 |
+
|
| 911 |
+
def environ(self):
|
| 912 |
+
"""The environment variables of the process as a dict. Note: this
|
| 913 |
+
might not reflect changes made after the process started.
|
| 914 |
+
"""
|
| 915 |
+
return self._proc.environ()
|
| 916 |
+
|
| 917 |
+
if WINDOWS:
|
| 918 |
+
|
| 919 |
+
def num_handles(self):
|
| 920 |
+
"""Return the number of handles opened by this process
|
| 921 |
+
(Windows only).
|
| 922 |
+
"""
|
| 923 |
+
return self._proc.num_handles()
|
| 924 |
+
|
| 925 |
+
def num_ctx_switches(self):
|
| 926 |
+
"""Return the number of voluntary and involuntary context
|
| 927 |
+
switches performed by this process.
|
| 928 |
+
"""
|
| 929 |
+
return self._proc.num_ctx_switches()
|
| 930 |
+
|
| 931 |
+
def num_threads(self):
|
| 932 |
+
"""Return the number of threads used by this process."""
|
| 933 |
+
return self._proc.num_threads()
|
| 934 |
+
|
| 935 |
+
if hasattr(_psplatform.Process, "threads"):
|
| 936 |
+
|
| 937 |
+
def threads(self):
|
| 938 |
+
"""Return threads opened by process as a list of
|
| 939 |
+
(id, user_time, system_time) namedtuples representing
|
| 940 |
+
thread id and thread CPU times (user/system).
|
| 941 |
+
On OpenBSD this method requires root access.
|
| 942 |
+
"""
|
| 943 |
+
return self._proc.threads()
|
| 944 |
+
|
| 945 |
+
def children(self, recursive=False):
|
| 946 |
+
"""Return the children of this process as a list of Process
|
| 947 |
+
instances, pre-emptively checking whether PID has been reused.
|
| 948 |
+
If *recursive* is True return all the parent descendants.
|
| 949 |
+
|
| 950 |
+
Example (A == this process):
|
| 951 |
+
|
| 952 |
+
A ─┐
|
| 953 |
+
│
|
| 954 |
+
├─ B (child) ─┐
|
| 955 |
+
│ └─ X (grandchild) ─┐
|
| 956 |
+
│ └─ Y (great grandchild)
|
| 957 |
+
├─ C (child)
|
| 958 |
+
└─ D (child)
|
| 959 |
+
|
| 960 |
+
>>> import psutil
|
| 961 |
+
>>> p = psutil.Process()
|
| 962 |
+
>>> p.children()
|
| 963 |
+
B, C, D
|
| 964 |
+
>>> p.children(recursive=True)
|
| 965 |
+
B, X, Y, C, D
|
| 966 |
+
|
| 967 |
+
Note that in the example above if process X disappears
|
| 968 |
+
process Y won't be listed as the reference to process A
|
| 969 |
+
is lost.
|
| 970 |
+
"""
|
| 971 |
+
self._raise_if_pid_reused()
|
| 972 |
+
ppid_map = _ppid_map()
|
| 973 |
+
ret = []
|
| 974 |
+
if not recursive:
|
| 975 |
+
for pid, ppid in ppid_map.items():
|
| 976 |
+
if ppid == self.pid:
|
| 977 |
+
try:
|
| 978 |
+
child = Process(pid)
|
| 979 |
+
# if child happens to be older than its parent
|
| 980 |
+
# (self) it means child's PID has been reused
|
| 981 |
+
if self.create_time() <= child.create_time():
|
| 982 |
+
ret.append(child)
|
| 983 |
+
except (NoSuchProcess, ZombieProcess):
|
| 984 |
+
pass
|
| 985 |
+
else:
|
| 986 |
+
# Construct a {pid: [child pids]} dict
|
| 987 |
+
reverse_ppid_map = collections.defaultdict(list)
|
| 988 |
+
for pid, ppid in ppid_map.items():
|
| 989 |
+
reverse_ppid_map[ppid].append(pid)
|
| 990 |
+
# Recursively traverse that dict, starting from self.pid,
|
| 991 |
+
# such that we only call Process() on actual children
|
| 992 |
+
seen = set()
|
| 993 |
+
stack = [self.pid]
|
| 994 |
+
while stack:
|
| 995 |
+
pid = stack.pop()
|
| 996 |
+
if pid in seen:
|
| 997 |
+
# Since pids can be reused while the ppid_map is
|
| 998 |
+
# constructed, there may be rare instances where
|
| 999 |
+
# there's a cycle in the recorded process "tree".
|
| 1000 |
+
continue
|
| 1001 |
+
seen.add(pid)
|
| 1002 |
+
for child_pid in reverse_ppid_map[pid]:
|
| 1003 |
+
try:
|
| 1004 |
+
child = Process(child_pid)
|
| 1005 |
+
# if child happens to be older than its parent
|
| 1006 |
+
# (self) it means child's PID has been reused
|
| 1007 |
+
intime = self.create_time() <= child.create_time()
|
| 1008 |
+
if intime:
|
| 1009 |
+
ret.append(child)
|
| 1010 |
+
stack.append(child_pid)
|
| 1011 |
+
except (NoSuchProcess, ZombieProcess):
|
| 1012 |
+
pass
|
| 1013 |
+
return ret
|
| 1014 |
+
|
| 1015 |
+
def cpu_percent(self, interval=None):
|
| 1016 |
+
"""Return a float representing the current process CPU
|
| 1017 |
+
utilization as a percentage.
|
| 1018 |
+
|
| 1019 |
+
When *interval* is 0.0 or None (default) compares process times
|
| 1020 |
+
to system CPU times elapsed since last call, returning
|
| 1021 |
+
immediately (non-blocking). That means that the first time
|
| 1022 |
+
this is called it will return a meaningful 0.0 value.
|
| 1023 |
+
|
| 1024 |
+
When *interval* is > 0.0 compares process times to system CPU
|
| 1025 |
+
times elapsed before and after the interval (blocking).
|
| 1026 |
+
|
| 1027 |
+
In this case is recommended for accuracy that this function
|
| 1028 |
+
be called with at least 0.1 seconds between calls.
|
| 1029 |
+
|
| 1030 |
+
A value > 100.0 can be returned in case of processes running
|
| 1031 |
+
multiple threads on different CPU cores.
|
| 1032 |
+
|
| 1033 |
+
The returned value is explicitly NOT split evenly between
|
| 1034 |
+
all available logical CPUs. This means that a busy loop process
|
| 1035 |
+
running on a system with 2 logical CPUs will be reported as
|
| 1036 |
+
having 100% CPU utilization instead of 50%.
|
| 1037 |
+
|
| 1038 |
+
Examples:
|
| 1039 |
+
|
| 1040 |
+
>>> import psutil
|
| 1041 |
+
>>> p = psutil.Process(os.getpid())
|
| 1042 |
+
>>> # blocking
|
| 1043 |
+
>>> p.cpu_percent(interval=1)
|
| 1044 |
+
2.0
|
| 1045 |
+
>>> # non-blocking (percentage since last call)
|
| 1046 |
+
>>> p.cpu_percent(interval=None)
|
| 1047 |
+
2.9
|
| 1048 |
+
>>>
|
| 1049 |
+
"""
|
| 1050 |
+
blocking = interval is not None and interval > 0.0
|
| 1051 |
+
if interval is not None and interval < 0:
|
| 1052 |
+
msg = "interval is not positive (got %r)" % interval
|
| 1053 |
+
raise ValueError(msg)
|
| 1054 |
+
num_cpus = cpu_count() or 1
|
| 1055 |
+
|
| 1056 |
+
def timer():
|
| 1057 |
+
return _timer() * num_cpus
|
| 1058 |
+
|
| 1059 |
+
if blocking:
|
| 1060 |
+
st1 = timer()
|
| 1061 |
+
pt1 = self._proc.cpu_times()
|
| 1062 |
+
time.sleep(interval)
|
| 1063 |
+
st2 = timer()
|
| 1064 |
+
pt2 = self._proc.cpu_times()
|
| 1065 |
+
else:
|
| 1066 |
+
st1 = self._last_sys_cpu_times
|
| 1067 |
+
pt1 = self._last_proc_cpu_times
|
| 1068 |
+
st2 = timer()
|
| 1069 |
+
pt2 = self._proc.cpu_times()
|
| 1070 |
+
if st1 is None or pt1 is None:
|
| 1071 |
+
self._last_sys_cpu_times = st2
|
| 1072 |
+
self._last_proc_cpu_times = pt2
|
| 1073 |
+
return 0.0
|
| 1074 |
+
|
| 1075 |
+
delta_proc = (pt2.user - pt1.user) + (pt2.system - pt1.system)
|
| 1076 |
+
delta_time = st2 - st1
|
| 1077 |
+
# reset values for next call in case of interval == None
|
| 1078 |
+
self._last_sys_cpu_times = st2
|
| 1079 |
+
self._last_proc_cpu_times = pt2
|
| 1080 |
+
|
| 1081 |
+
try:
|
| 1082 |
+
# This is the utilization split evenly between all CPUs.
|
| 1083 |
+
# E.g. a busy loop process on a 2-CPU-cores system at this
|
| 1084 |
+
# point is reported as 50% instead of 100%.
|
| 1085 |
+
overall_cpus_percent = (delta_proc / delta_time) * 100
|
| 1086 |
+
except ZeroDivisionError:
|
| 1087 |
+
# interval was too low
|
| 1088 |
+
return 0.0
|
| 1089 |
+
else:
|
| 1090 |
+
# Note 1:
|
| 1091 |
+
# in order to emulate "top" we multiply the value for the num
|
| 1092 |
+
# of CPU cores. This way the busy process will be reported as
|
| 1093 |
+
# having 100% (or more) usage.
|
| 1094 |
+
#
|
| 1095 |
+
# Note 2:
|
| 1096 |
+
# taskmgr.exe on Windows differs in that it will show 50%
|
| 1097 |
+
# instead.
|
| 1098 |
+
#
|
| 1099 |
+
# Note 3:
|
| 1100 |
+
# a percentage > 100 is legitimate as it can result from a
|
| 1101 |
+
# process with multiple threads running on different CPU
|
| 1102 |
+
# cores (top does the same), see:
|
| 1103 |
+
# http://stackoverflow.com/questions/1032357
|
| 1104 |
+
# https://github.com/giampaolo/psutil/issues/474
|
| 1105 |
+
single_cpu_percent = overall_cpus_percent * num_cpus
|
| 1106 |
+
return round(single_cpu_percent, 1)
|
| 1107 |
+
|
| 1108 |
+
@memoize_when_activated
|
| 1109 |
+
def cpu_times(self):
|
| 1110 |
+
"""Return a (user, system, children_user, children_system)
|
| 1111 |
+
namedtuple representing the accumulated process time, in
|
| 1112 |
+
seconds.
|
| 1113 |
+
This is similar to os.times() but per-process.
|
| 1114 |
+
On macOS and Windows children_user and children_system are
|
| 1115 |
+
always set to 0.
|
| 1116 |
+
"""
|
| 1117 |
+
return self._proc.cpu_times()
|
| 1118 |
+
|
| 1119 |
+
@memoize_when_activated
|
| 1120 |
+
def memory_info(self):
|
| 1121 |
+
"""Return a namedtuple with variable fields depending on the
|
| 1122 |
+
platform, representing memory information about the process.
|
| 1123 |
+
|
| 1124 |
+
The "portable" fields available on all platforms are `rss` and `vms`.
|
| 1125 |
+
|
| 1126 |
+
All numbers are expressed in bytes.
|
| 1127 |
+
"""
|
| 1128 |
+
return self._proc.memory_info()
|
| 1129 |
+
|
| 1130 |
+
@_common.deprecated_method(replacement="memory_info")
|
| 1131 |
+
def memory_info_ex(self):
|
| 1132 |
+
return self.memory_info()
|
| 1133 |
+
|
| 1134 |
+
def memory_full_info(self):
|
| 1135 |
+
"""This method returns the same information as memory_info(),
|
| 1136 |
+
plus, on some platform (Linux, macOS, Windows), also provides
|
| 1137 |
+
additional metrics (USS, PSS and swap).
|
| 1138 |
+
The additional metrics provide a better representation of actual
|
| 1139 |
+
process memory usage.
|
| 1140 |
+
|
| 1141 |
+
Namely USS is the memory which is unique to a process and which
|
| 1142 |
+
would be freed if the process was terminated right now.
|
| 1143 |
+
|
| 1144 |
+
It does so by passing through the whole process address.
|
| 1145 |
+
As such it usually requires higher user privileges than
|
| 1146 |
+
memory_info() and is considerably slower.
|
| 1147 |
+
"""
|
| 1148 |
+
return self._proc.memory_full_info()
|
| 1149 |
+
|
| 1150 |
+
def memory_percent(self, memtype="rss"):
|
| 1151 |
+
"""Compare process memory to total physical system memory and
|
| 1152 |
+
calculate process memory utilization as a percentage.
|
| 1153 |
+
*memtype* argument is a string that dictates what type of
|
| 1154 |
+
process memory you want to compare against (defaults to "rss").
|
| 1155 |
+
The list of available strings can be obtained like this:
|
| 1156 |
+
|
| 1157 |
+
>>> psutil.Process().memory_info()._fields
|
| 1158 |
+
('rss', 'vms', 'shared', 'text', 'lib', 'data', 'dirty', 'uss', 'pss')
|
| 1159 |
+
"""
|
| 1160 |
+
valid_types = list(_psplatform.pfullmem._fields)
|
| 1161 |
+
if memtype not in valid_types:
|
| 1162 |
+
msg = "invalid memtype %r; valid types are %r" % (
|
| 1163 |
+
memtype,
|
| 1164 |
+
tuple(valid_types),
|
| 1165 |
+
)
|
| 1166 |
+
raise ValueError(msg)
|
| 1167 |
+
fun = (
|
| 1168 |
+
self.memory_info
|
| 1169 |
+
if memtype in _psplatform.pmem._fields
|
| 1170 |
+
else self.memory_full_info
|
| 1171 |
+
)
|
| 1172 |
+
metrics = fun()
|
| 1173 |
+
value = getattr(metrics, memtype)
|
| 1174 |
+
|
| 1175 |
+
# use cached value if available
|
| 1176 |
+
total_phymem = _TOTAL_PHYMEM or virtual_memory().total
|
| 1177 |
+
if not total_phymem > 0:
|
| 1178 |
+
# we should never get here
|
| 1179 |
+
msg = (
|
| 1180 |
+
"can't calculate process memory percent because total physical"
|
| 1181 |
+
" system memory is not positive (%r)" % (total_phymem)
|
| 1182 |
+
)
|
| 1183 |
+
raise ValueError(msg)
|
| 1184 |
+
return (value / float(total_phymem)) * 100
|
| 1185 |
+
|
| 1186 |
+
if hasattr(_psplatform.Process, "memory_maps"):
|
| 1187 |
+
|
| 1188 |
+
def memory_maps(self, grouped=True):
|
| 1189 |
+
"""Return process' mapped memory regions as a list of namedtuples
|
| 1190 |
+
whose fields are variable depending on the platform.
|
| 1191 |
+
|
| 1192 |
+
If *grouped* is True the mapped regions with the same 'path'
|
| 1193 |
+
are grouped together and the different memory fields are summed.
|
| 1194 |
+
|
| 1195 |
+
If *grouped* is False every mapped region is shown as a single
|
| 1196 |
+
entity and the namedtuple will also include the mapped region's
|
| 1197 |
+
address space ('addr') and permission set ('perms').
|
| 1198 |
+
"""
|
| 1199 |
+
it = self._proc.memory_maps()
|
| 1200 |
+
if grouped:
|
| 1201 |
+
d = {}
|
| 1202 |
+
for tupl in it:
|
| 1203 |
+
path = tupl[2]
|
| 1204 |
+
nums = tupl[3:]
|
| 1205 |
+
try:
|
| 1206 |
+
d[path] = map(lambda x, y: x + y, d[path], nums)
|
| 1207 |
+
except KeyError:
|
| 1208 |
+
d[path] = nums
|
| 1209 |
+
nt = _psplatform.pmmap_grouped
|
| 1210 |
+
return [nt(path, *d[path]) for path in d] # NOQA
|
| 1211 |
+
else:
|
| 1212 |
+
nt = _psplatform.pmmap_ext
|
| 1213 |
+
return [nt(*x) for x in it]
|
| 1214 |
+
|
| 1215 |
+
def open_files(self):
|
| 1216 |
+
"""Return files opened by process as a list of
|
| 1217 |
+
(path, fd) namedtuples including the absolute file name
|
| 1218 |
+
and file descriptor number.
|
| 1219 |
+
"""
|
| 1220 |
+
return self._proc.open_files()
|
| 1221 |
+
|
| 1222 |
+
def net_connections(self, kind='inet'):
|
| 1223 |
+
"""Return socket connections opened by process as a list of
|
| 1224 |
+
(fd, family, type, laddr, raddr, status) namedtuples.
|
| 1225 |
+
The *kind* parameter filters for connections that match the
|
| 1226 |
+
following criteria:
|
| 1227 |
+
|
| 1228 |
+
+------------+----------------------------------------------------+
|
| 1229 |
+
| Kind Value | Connections using |
|
| 1230 |
+
+------------+----------------------------------------------------+
|
| 1231 |
+
| inet | IPv4 and IPv6 |
|
| 1232 |
+
| inet4 | IPv4 |
|
| 1233 |
+
| inet6 | IPv6 |
|
| 1234 |
+
| tcp | TCP |
|
| 1235 |
+
| tcp4 | TCP over IPv4 |
|
| 1236 |
+
| tcp6 | TCP over IPv6 |
|
| 1237 |
+
| udp | UDP |
|
| 1238 |
+
| udp4 | UDP over IPv4 |
|
| 1239 |
+
| udp6 | UDP over IPv6 |
|
| 1240 |
+
| unix | UNIX socket (both UDP and TCP protocols) |
|
| 1241 |
+
| all | the sum of all the possible families and protocols |
|
| 1242 |
+
+------------+----------------------------------------------------+
|
| 1243 |
+
"""
|
| 1244 |
+
return self._proc.net_connections(kind)
|
| 1245 |
+
|
| 1246 |
+
@_common.deprecated_method(replacement="net_connections")
|
| 1247 |
+
def connections(self, kind="inet"):
|
| 1248 |
+
return self.net_connections(kind=kind)
|
| 1249 |
+
|
| 1250 |
+
# --- signals
|
| 1251 |
+
|
| 1252 |
+
if POSIX:
|
| 1253 |
+
|
| 1254 |
+
def _send_signal(self, sig):
|
| 1255 |
+
assert not self.pid < 0, self.pid
|
| 1256 |
+
self._raise_if_pid_reused()
|
| 1257 |
+
if self.pid == 0:
|
| 1258 |
+
# see "man 2 kill"
|
| 1259 |
+
msg = (
|
| 1260 |
+
"preventing sending signal to process with PID 0 as it "
|
| 1261 |
+
"would affect every process in the process group of the "
|
| 1262 |
+
"calling process (os.getpid()) instead of PID 0"
|
| 1263 |
+
)
|
| 1264 |
+
raise ValueError(msg)
|
| 1265 |
+
try:
|
| 1266 |
+
os.kill(self.pid, sig)
|
| 1267 |
+
except ProcessLookupError:
|
| 1268 |
+
if OPENBSD and pid_exists(self.pid):
|
| 1269 |
+
# We do this because os.kill() lies in case of
|
| 1270 |
+
# zombie processes.
|
| 1271 |
+
raise ZombieProcess(self.pid, self._name, self._ppid)
|
| 1272 |
+
else:
|
| 1273 |
+
self._gone = True
|
| 1274 |
+
raise NoSuchProcess(self.pid, self._name)
|
| 1275 |
+
except PermissionError:
|
| 1276 |
+
raise AccessDenied(self.pid, self._name)
|
| 1277 |
+
|
| 1278 |
+
def send_signal(self, sig):
|
| 1279 |
+
"""Send a signal *sig* to process pre-emptively checking
|
| 1280 |
+
whether PID has been reused (see signal module constants) .
|
| 1281 |
+
On Windows only SIGTERM is valid and is treated as an alias
|
| 1282 |
+
for kill().
|
| 1283 |
+
"""
|
| 1284 |
+
if POSIX:
|
| 1285 |
+
self._send_signal(sig)
|
| 1286 |
+
else: # pragma: no cover
|
| 1287 |
+
self._raise_if_pid_reused()
|
| 1288 |
+
if sig != signal.SIGTERM and not self.is_running():
|
| 1289 |
+
msg = "process no longer exists"
|
| 1290 |
+
raise NoSuchProcess(self.pid, self._name, msg=msg)
|
| 1291 |
+
self._proc.send_signal(sig)
|
| 1292 |
+
|
| 1293 |
+
def suspend(self):
|
| 1294 |
+
"""Suspend process execution with SIGSTOP pre-emptively checking
|
| 1295 |
+
whether PID has been reused.
|
| 1296 |
+
On Windows this has the effect of suspending all process threads.
|
| 1297 |
+
"""
|
| 1298 |
+
if POSIX:
|
| 1299 |
+
self._send_signal(signal.SIGSTOP)
|
| 1300 |
+
else: # pragma: no cover
|
| 1301 |
+
self._raise_if_pid_reused()
|
| 1302 |
+
self._proc.suspend()
|
| 1303 |
+
|
| 1304 |
+
def resume(self):
|
| 1305 |
+
"""Resume process execution with SIGCONT pre-emptively checking
|
| 1306 |
+
whether PID has been reused.
|
| 1307 |
+
On Windows this has the effect of resuming all process threads.
|
| 1308 |
+
"""
|
| 1309 |
+
if POSIX:
|
| 1310 |
+
self._send_signal(signal.SIGCONT)
|
| 1311 |
+
else: # pragma: no cover
|
| 1312 |
+
self._raise_if_pid_reused()
|
| 1313 |
+
self._proc.resume()
|
| 1314 |
+
|
| 1315 |
+
def terminate(self):
|
| 1316 |
+
"""Terminate the process with SIGTERM pre-emptively checking
|
| 1317 |
+
whether PID has been reused.
|
| 1318 |
+
On Windows this is an alias for kill().
|
| 1319 |
+
"""
|
| 1320 |
+
if POSIX:
|
| 1321 |
+
self._send_signal(signal.SIGTERM)
|
| 1322 |
+
else: # pragma: no cover
|
| 1323 |
+
self._raise_if_pid_reused()
|
| 1324 |
+
self._proc.kill()
|
| 1325 |
+
|
| 1326 |
+
def kill(self):
|
| 1327 |
+
"""Kill the current process with SIGKILL pre-emptively checking
|
| 1328 |
+
whether PID has been reused.
|
| 1329 |
+
"""
|
| 1330 |
+
if POSIX:
|
| 1331 |
+
self._send_signal(signal.SIGKILL)
|
| 1332 |
+
else: # pragma: no cover
|
| 1333 |
+
self._raise_if_pid_reused()
|
| 1334 |
+
self._proc.kill()
|
| 1335 |
+
|
| 1336 |
+
def wait(self, timeout=None):
|
| 1337 |
+
"""Wait for process to terminate and, if process is a children
|
| 1338 |
+
of os.getpid(), also return its exit code, else None.
|
| 1339 |
+
On Windows there's no such limitation (exit code is always
|
| 1340 |
+
returned).
|
| 1341 |
+
|
| 1342 |
+
If the process is already terminated immediately return None
|
| 1343 |
+
instead of raising NoSuchProcess.
|
| 1344 |
+
|
| 1345 |
+
If *timeout* (in seconds) is specified and process is still
|
| 1346 |
+
alive raise TimeoutExpired.
|
| 1347 |
+
|
| 1348 |
+
To wait for multiple Process(es) use psutil.wait_procs().
|
| 1349 |
+
"""
|
| 1350 |
+
if timeout is not None and not timeout >= 0:
|
| 1351 |
+
msg = "timeout must be a positive integer"
|
| 1352 |
+
raise ValueError(msg)
|
| 1353 |
+
if self._exitcode is not _SENTINEL:
|
| 1354 |
+
return self._exitcode
|
| 1355 |
+
self._exitcode = self._proc.wait(timeout)
|
| 1356 |
+
return self._exitcode
|
| 1357 |
+
|
| 1358 |
+
|
| 1359 |
+
# The valid attr names which can be processed by Process.as_dict().
|
| 1360 |
+
# fmt: off
|
| 1361 |
+
_as_dict_attrnames = set(
|
| 1362 |
+
[x for x in dir(Process) if not x.startswith('_') and x not in
|
| 1363 |
+
{'send_signal', 'suspend', 'resume', 'terminate', 'kill', 'wait',
|
| 1364 |
+
'is_running', 'as_dict', 'parent', 'parents', 'children', 'rlimit',
|
| 1365 |
+
'memory_info_ex', 'connections', 'oneshot'}])
|
| 1366 |
+
# fmt: on
|
| 1367 |
+
|
| 1368 |
+
|
| 1369 |
+
# =====================================================================
|
| 1370 |
+
# --- Popen class
|
| 1371 |
+
# =====================================================================
|
| 1372 |
+
|
| 1373 |
+
|
| 1374 |
+
class Popen(Process):
|
| 1375 |
+
"""Same as subprocess.Popen, but in addition it provides all
|
| 1376 |
+
psutil.Process methods in a single class.
|
| 1377 |
+
For the following methods which are common to both classes, psutil
|
| 1378 |
+
implementation takes precedence:
|
| 1379 |
+
|
| 1380 |
+
* send_signal()
|
| 1381 |
+
* terminate()
|
| 1382 |
+
* kill()
|
| 1383 |
+
|
| 1384 |
+
This is done in order to avoid killing another process in case its
|
| 1385 |
+
PID has been reused, fixing BPO-6973.
|
| 1386 |
+
|
| 1387 |
+
>>> import psutil
|
| 1388 |
+
>>> from subprocess import PIPE
|
| 1389 |
+
>>> p = psutil.Popen(["python", "-c", "print 'hi'"], stdout=PIPE)
|
| 1390 |
+
>>> p.name()
|
| 1391 |
+
'python'
|
| 1392 |
+
>>> p.uids()
|
| 1393 |
+
user(real=1000, effective=1000, saved=1000)
|
| 1394 |
+
>>> p.username()
|
| 1395 |
+
'giampaolo'
|
| 1396 |
+
>>> p.communicate()
|
| 1397 |
+
('hi', None)
|
| 1398 |
+
>>> p.terminate()
|
| 1399 |
+
>>> p.wait(timeout=2)
|
| 1400 |
+
0
|
| 1401 |
+
>>>
|
| 1402 |
+
"""
|
| 1403 |
+
|
| 1404 |
+
def __init__(self, *args, **kwargs):
|
| 1405 |
+
# Explicitly avoid to raise NoSuchProcess in case the process
|
| 1406 |
+
# spawned by subprocess.Popen terminates too quickly, see:
|
| 1407 |
+
# https://github.com/giampaolo/psutil/issues/193
|
| 1408 |
+
self.__subproc = subprocess.Popen(*args, **kwargs)
|
| 1409 |
+
self._init(self.__subproc.pid, _ignore_nsp=True)
|
| 1410 |
+
|
| 1411 |
+
def __dir__(self):
|
| 1412 |
+
return sorted(set(dir(Popen) + dir(subprocess.Popen)))
|
| 1413 |
+
|
| 1414 |
+
def __enter__(self):
|
| 1415 |
+
if hasattr(self.__subproc, '__enter__'):
|
| 1416 |
+
self.__subproc.__enter__()
|
| 1417 |
+
return self
|
| 1418 |
+
|
| 1419 |
+
def __exit__(self, *args, **kwargs):
|
| 1420 |
+
if hasattr(self.__subproc, '__exit__'):
|
| 1421 |
+
return self.__subproc.__exit__(*args, **kwargs)
|
| 1422 |
+
else:
|
| 1423 |
+
if self.stdout:
|
| 1424 |
+
self.stdout.close()
|
| 1425 |
+
if self.stderr:
|
| 1426 |
+
self.stderr.close()
|
| 1427 |
+
try:
|
| 1428 |
+
# Flushing a BufferedWriter may raise an error.
|
| 1429 |
+
if self.stdin:
|
| 1430 |
+
self.stdin.close()
|
| 1431 |
+
finally:
|
| 1432 |
+
# Wait for the process to terminate, to avoid zombies.
|
| 1433 |
+
self.wait()
|
| 1434 |
+
|
| 1435 |
+
def __getattribute__(self, name):
|
| 1436 |
+
try:
|
| 1437 |
+
return object.__getattribute__(self, name)
|
| 1438 |
+
except AttributeError:
|
| 1439 |
+
try:
|
| 1440 |
+
return object.__getattribute__(self.__subproc, name)
|
| 1441 |
+
except AttributeError:
|
| 1442 |
+
msg = "%s instance has no attribute '%s'" % (
|
| 1443 |
+
self.__class__.__name__,
|
| 1444 |
+
name,
|
| 1445 |
+
)
|
| 1446 |
+
raise AttributeError(msg)
|
| 1447 |
+
|
| 1448 |
+
def wait(self, timeout=None):
|
| 1449 |
+
if self.__subproc.returncode is not None:
|
| 1450 |
+
return self.__subproc.returncode
|
| 1451 |
+
ret = super(Popen, self).wait(timeout) # noqa
|
| 1452 |
+
self.__subproc.returncode = ret
|
| 1453 |
+
return ret
|
| 1454 |
+
|
| 1455 |
+
|
| 1456 |
+
# =====================================================================
|
| 1457 |
+
# --- system processes related functions
|
| 1458 |
+
# =====================================================================
|
| 1459 |
+
|
| 1460 |
+
|
| 1461 |
+
def pids():
|
| 1462 |
+
"""Return a list of current running PIDs."""
|
| 1463 |
+
global _LOWEST_PID
|
| 1464 |
+
ret = sorted(_psplatform.pids())
|
| 1465 |
+
_LOWEST_PID = ret[0]
|
| 1466 |
+
return ret
|
| 1467 |
+
|
| 1468 |
+
|
| 1469 |
+
def pid_exists(pid):
|
| 1470 |
+
"""Return True if given PID exists in the current process list.
|
| 1471 |
+
This is faster than doing "pid in psutil.pids()" and
|
| 1472 |
+
should be preferred.
|
| 1473 |
+
"""
|
| 1474 |
+
if pid < 0:
|
| 1475 |
+
return False
|
| 1476 |
+
elif pid == 0 and POSIX:
|
| 1477 |
+
# On POSIX we use os.kill() to determine PID existence.
|
| 1478 |
+
# According to "man 2 kill" PID 0 has a special meaning
|
| 1479 |
+
# though: it refers to <<every process in the process
|
| 1480 |
+
# group of the calling process>> and that is not we want
|
| 1481 |
+
# to do here.
|
| 1482 |
+
return pid in pids()
|
| 1483 |
+
else:
|
| 1484 |
+
return _psplatform.pid_exists(pid)
|
| 1485 |
+
|
| 1486 |
+
|
| 1487 |
+
_pmap = {}
|
| 1488 |
+
_pids_reused = set()
|
| 1489 |
+
|
| 1490 |
+
|
| 1491 |
+
def process_iter(attrs=None, ad_value=None):
|
| 1492 |
+
"""Return a generator yielding a Process instance for all
|
| 1493 |
+
running processes.
|
| 1494 |
+
|
| 1495 |
+
Every new Process instance is only created once and then cached
|
| 1496 |
+
into an internal table which is updated every time this is used.
|
| 1497 |
+
Cache can optionally be cleared via `process_iter.clear_cache()`.
|
| 1498 |
+
|
| 1499 |
+
The sorting order in which processes are yielded is based on
|
| 1500 |
+
their PIDs.
|
| 1501 |
+
|
| 1502 |
+
*attrs* and *ad_value* have the same meaning as in
|
| 1503 |
+
Process.as_dict(). If *attrs* is specified as_dict() is called
|
| 1504 |
+
and the resulting dict is stored as a 'info' attribute attached
|
| 1505 |
+
to returned Process instance.
|
| 1506 |
+
If *attrs* is an empty list it will retrieve all process info
|
| 1507 |
+
(slow).
|
| 1508 |
+
"""
|
| 1509 |
+
global _pmap
|
| 1510 |
+
|
| 1511 |
+
def add(pid):
|
| 1512 |
+
proc = Process(pid)
|
| 1513 |
+
pmap[proc.pid] = proc
|
| 1514 |
+
return proc
|
| 1515 |
+
|
| 1516 |
+
def remove(pid):
|
| 1517 |
+
pmap.pop(pid, None)
|
| 1518 |
+
|
| 1519 |
+
pmap = _pmap.copy()
|
| 1520 |
+
a = set(pids())
|
| 1521 |
+
b = set(pmap.keys())
|
| 1522 |
+
new_pids = a - b
|
| 1523 |
+
gone_pids = b - a
|
| 1524 |
+
for pid in gone_pids:
|
| 1525 |
+
remove(pid)
|
| 1526 |
+
while _pids_reused:
|
| 1527 |
+
pid = _pids_reused.pop()
|
| 1528 |
+
debug("refreshing Process instance for reused PID %s" % pid)
|
| 1529 |
+
remove(pid)
|
| 1530 |
+
try:
|
| 1531 |
+
ls = sorted(list(pmap.items()) + list(dict.fromkeys(new_pids).items()))
|
| 1532 |
+
for pid, proc in ls:
|
| 1533 |
+
try:
|
| 1534 |
+
if proc is None: # new process
|
| 1535 |
+
proc = add(pid)
|
| 1536 |
+
if attrs is not None:
|
| 1537 |
+
proc.info = proc.as_dict(attrs=attrs, ad_value=ad_value)
|
| 1538 |
+
yield proc
|
| 1539 |
+
except NoSuchProcess:
|
| 1540 |
+
remove(pid)
|
| 1541 |
+
finally:
|
| 1542 |
+
_pmap = pmap
|
| 1543 |
+
|
| 1544 |
+
|
| 1545 |
+
process_iter.cache_clear = lambda: _pmap.clear() # noqa
|
| 1546 |
+
process_iter.cache_clear.__doc__ = "Clear process_iter() internal cache."
|
| 1547 |
+
|
| 1548 |
+
|
| 1549 |
+
def wait_procs(procs, timeout=None, callback=None):
|
| 1550 |
+
"""Convenience function which waits for a list of processes to
|
| 1551 |
+
terminate.
|
| 1552 |
+
|
| 1553 |
+
Return a (gone, alive) tuple indicating which processes
|
| 1554 |
+
are gone and which ones are still alive.
|
| 1555 |
+
|
| 1556 |
+
The gone ones will have a new *returncode* attribute indicating
|
| 1557 |
+
process exit status (may be None).
|
| 1558 |
+
|
| 1559 |
+
*callback* is a function which gets called every time a process
|
| 1560 |
+
terminates (a Process instance is passed as callback argument).
|
| 1561 |
+
|
| 1562 |
+
Function will return as soon as all processes terminate or when
|
| 1563 |
+
*timeout* occurs.
|
| 1564 |
+
Differently from Process.wait() it will not raise TimeoutExpired if
|
| 1565 |
+
*timeout* occurs.
|
| 1566 |
+
|
| 1567 |
+
Typical use case is:
|
| 1568 |
+
|
| 1569 |
+
- send SIGTERM to a list of processes
|
| 1570 |
+
- give them some time to terminate
|
| 1571 |
+
- send SIGKILL to those ones which are still alive
|
| 1572 |
+
|
| 1573 |
+
Example:
|
| 1574 |
+
|
| 1575 |
+
>>> def on_terminate(proc):
|
| 1576 |
+
... print("process {} terminated".format(proc))
|
| 1577 |
+
...
|
| 1578 |
+
>>> for p in procs:
|
| 1579 |
+
... p.terminate()
|
| 1580 |
+
...
|
| 1581 |
+
>>> gone, alive = wait_procs(procs, timeout=3, callback=on_terminate)
|
| 1582 |
+
>>> for p in alive:
|
| 1583 |
+
... p.kill()
|
| 1584 |
+
"""
|
| 1585 |
+
|
| 1586 |
+
def check_gone(proc, timeout):
|
| 1587 |
+
try:
|
| 1588 |
+
returncode = proc.wait(timeout=timeout)
|
| 1589 |
+
except TimeoutExpired:
|
| 1590 |
+
pass
|
| 1591 |
+
except _SubprocessTimeoutExpired:
|
| 1592 |
+
pass
|
| 1593 |
+
else:
|
| 1594 |
+
if returncode is not None or not proc.is_running():
|
| 1595 |
+
# Set new Process instance attribute.
|
| 1596 |
+
proc.returncode = returncode
|
| 1597 |
+
gone.add(proc)
|
| 1598 |
+
if callback is not None:
|
| 1599 |
+
callback(proc)
|
| 1600 |
+
|
| 1601 |
+
if timeout is not None and not timeout >= 0:
|
| 1602 |
+
msg = "timeout must be a positive integer, got %s" % timeout
|
| 1603 |
+
raise ValueError(msg)
|
| 1604 |
+
gone = set()
|
| 1605 |
+
alive = set(procs)
|
| 1606 |
+
if callback is not None and not callable(callback):
|
| 1607 |
+
msg = "callback %r is not a callable" % callback
|
| 1608 |
+
raise TypeError(msg)
|
| 1609 |
+
if timeout is not None:
|
| 1610 |
+
deadline = _timer() + timeout
|
| 1611 |
+
|
| 1612 |
+
while alive:
|
| 1613 |
+
if timeout is not None and timeout <= 0:
|
| 1614 |
+
break
|
| 1615 |
+
for proc in alive:
|
| 1616 |
+
# Make sure that every complete iteration (all processes)
|
| 1617 |
+
# will last max 1 sec.
|
| 1618 |
+
# We do this because we don't want to wait too long on a
|
| 1619 |
+
# single process: in case it terminates too late other
|
| 1620 |
+
# processes may disappear in the meantime and their PID
|
| 1621 |
+
# reused.
|
| 1622 |
+
max_timeout = 1.0 / len(alive)
|
| 1623 |
+
if timeout is not None:
|
| 1624 |
+
timeout = min((deadline - _timer()), max_timeout)
|
| 1625 |
+
if timeout <= 0:
|
| 1626 |
+
break
|
| 1627 |
+
check_gone(proc, timeout)
|
| 1628 |
+
else:
|
| 1629 |
+
check_gone(proc, max_timeout)
|
| 1630 |
+
alive = alive - gone # noqa PLR6104
|
| 1631 |
+
|
| 1632 |
+
if alive:
|
| 1633 |
+
# Last attempt over processes survived so far.
|
| 1634 |
+
# timeout == 0 won't make this function wait any further.
|
| 1635 |
+
for proc in alive:
|
| 1636 |
+
check_gone(proc, 0)
|
| 1637 |
+
alive = alive - gone # noqa: PLR6104
|
| 1638 |
+
|
| 1639 |
+
return (list(gone), list(alive))
|
| 1640 |
+
|
| 1641 |
+
|
| 1642 |
+
# =====================================================================
|
| 1643 |
+
# --- CPU related functions
|
| 1644 |
+
# =====================================================================
|
| 1645 |
+
|
| 1646 |
+
|
| 1647 |
+
def cpu_count(logical=True):
|
| 1648 |
+
"""Return the number of logical CPUs in the system (same as
|
| 1649 |
+
os.cpu_count() in Python 3.4).
|
| 1650 |
+
|
| 1651 |
+
If *logical* is False return the number of physical cores only
|
| 1652 |
+
(e.g. hyper thread CPUs are excluded).
|
| 1653 |
+
|
| 1654 |
+
Return None if undetermined.
|
| 1655 |
+
|
| 1656 |
+
The return value is cached after first call.
|
| 1657 |
+
If desired cache can be cleared like this:
|
| 1658 |
+
|
| 1659 |
+
>>> psutil.cpu_count.cache_clear()
|
| 1660 |
+
"""
|
| 1661 |
+
if logical:
|
| 1662 |
+
ret = _psplatform.cpu_count_logical()
|
| 1663 |
+
else:
|
| 1664 |
+
ret = _psplatform.cpu_count_cores()
|
| 1665 |
+
if ret is not None and ret < 1:
|
| 1666 |
+
ret = None
|
| 1667 |
+
return ret
|
| 1668 |
+
|
| 1669 |
+
|
| 1670 |
+
def cpu_times(percpu=False):
|
| 1671 |
+
"""Return system-wide CPU times as a namedtuple.
|
| 1672 |
+
Every CPU time represents the seconds the CPU has spent in the
|
| 1673 |
+
given mode. The namedtuple's fields availability varies depending on the
|
| 1674 |
+
platform:
|
| 1675 |
+
|
| 1676 |
+
- user
|
| 1677 |
+
- system
|
| 1678 |
+
- idle
|
| 1679 |
+
- nice (UNIX)
|
| 1680 |
+
- iowait (Linux)
|
| 1681 |
+
- irq (Linux, FreeBSD)
|
| 1682 |
+
- softirq (Linux)
|
| 1683 |
+
- steal (Linux >= 2.6.11)
|
| 1684 |
+
- guest (Linux >= 2.6.24)
|
| 1685 |
+
- guest_nice (Linux >= 3.2.0)
|
| 1686 |
+
|
| 1687 |
+
When *percpu* is True return a list of namedtuples for each CPU.
|
| 1688 |
+
First element of the list refers to first CPU, second element
|
| 1689 |
+
to second CPU and so on.
|
| 1690 |
+
The order of the list is consistent across calls.
|
| 1691 |
+
"""
|
| 1692 |
+
if not percpu:
|
| 1693 |
+
return _psplatform.cpu_times()
|
| 1694 |
+
else:
|
| 1695 |
+
return _psplatform.per_cpu_times()
|
| 1696 |
+
|
| 1697 |
+
|
| 1698 |
+
try:
|
| 1699 |
+
_last_cpu_times = {threading.current_thread().ident: cpu_times()}
|
| 1700 |
+
except Exception: # noqa: BLE001
|
| 1701 |
+
# Don't want to crash at import time.
|
| 1702 |
+
_last_cpu_times = {}
|
| 1703 |
+
|
| 1704 |
+
try:
|
| 1705 |
+
_last_per_cpu_times = {
|
| 1706 |
+
threading.current_thread().ident: cpu_times(percpu=True)
|
| 1707 |
+
}
|
| 1708 |
+
except Exception: # noqa: BLE001
|
| 1709 |
+
# Don't want to crash at import time.
|
| 1710 |
+
_last_per_cpu_times = {}
|
| 1711 |
+
|
| 1712 |
+
|
| 1713 |
+
def _cpu_tot_time(times):
|
| 1714 |
+
"""Given a cpu_time() ntuple calculates the total CPU time
|
| 1715 |
+
(including idle time).
|
| 1716 |
+
"""
|
| 1717 |
+
tot = sum(times)
|
| 1718 |
+
if LINUX:
|
| 1719 |
+
# On Linux guest times are already accounted in "user" or
|
| 1720 |
+
# "nice" times, so we subtract them from total.
|
| 1721 |
+
# Htop does the same. References:
|
| 1722 |
+
# https://github.com/giampaolo/psutil/pull/940
|
| 1723 |
+
# http://unix.stackexchange.com/questions/178045
|
| 1724 |
+
# https://github.com/torvalds/linux/blob/
|
| 1725 |
+
# 447976ef4fd09b1be88b316d1a81553f1aa7cd07/kernel/sched/
|
| 1726 |
+
# cputime.c#L158
|
| 1727 |
+
tot -= getattr(times, "guest", 0) # Linux 2.6.24+
|
| 1728 |
+
tot -= getattr(times, "guest_nice", 0) # Linux 3.2.0+
|
| 1729 |
+
return tot
|
| 1730 |
+
|
| 1731 |
+
|
| 1732 |
+
def _cpu_busy_time(times):
|
| 1733 |
+
"""Given a cpu_time() ntuple calculates the busy CPU time.
|
| 1734 |
+
We do so by subtracting all idle CPU times.
|
| 1735 |
+
"""
|
| 1736 |
+
busy = _cpu_tot_time(times)
|
| 1737 |
+
busy -= times.idle
|
| 1738 |
+
# Linux: "iowait" is time during which the CPU does not do anything
|
| 1739 |
+
# (waits for IO to complete). On Linux IO wait is *not* accounted
|
| 1740 |
+
# in "idle" time so we subtract it. Htop does the same.
|
| 1741 |
+
# References:
|
| 1742 |
+
# https://github.com/torvalds/linux/blob/
|
| 1743 |
+
# 447976ef4fd09b1be88b316d1a81553f1aa7cd07/kernel/sched/cputime.c#L244
|
| 1744 |
+
busy -= getattr(times, "iowait", 0)
|
| 1745 |
+
return busy
|
| 1746 |
+
|
| 1747 |
+
|
| 1748 |
+
def _cpu_times_deltas(t1, t2):
|
| 1749 |
+
assert t1._fields == t2._fields, (t1, t2)
|
| 1750 |
+
field_deltas = []
|
| 1751 |
+
for field in _psplatform.scputimes._fields:
|
| 1752 |
+
field_delta = getattr(t2, field) - getattr(t1, field)
|
| 1753 |
+
# CPU times are always supposed to increase over time
|
| 1754 |
+
# or at least remain the same and that's because time
|
| 1755 |
+
# cannot go backwards.
|
| 1756 |
+
# Surprisingly sometimes this might not be the case (at
|
| 1757 |
+
# least on Windows and Linux), see:
|
| 1758 |
+
# https://github.com/giampaolo/psutil/issues/392
|
| 1759 |
+
# https://github.com/giampaolo/psutil/issues/645
|
| 1760 |
+
# https://github.com/giampaolo/psutil/issues/1210
|
| 1761 |
+
# Trim negative deltas to zero to ignore decreasing fields.
|
| 1762 |
+
# top does the same. Reference:
|
| 1763 |
+
# https://gitlab.com/procps-ng/procps/blob/v3.3.12/top/top.c#L5063
|
| 1764 |
+
field_delta = max(0, field_delta)
|
| 1765 |
+
field_deltas.append(field_delta)
|
| 1766 |
+
return _psplatform.scputimes(*field_deltas)
|
| 1767 |
+
|
| 1768 |
+
|
| 1769 |
+
def cpu_percent(interval=None, percpu=False):
|
| 1770 |
+
"""Return a float representing the current system-wide CPU
|
| 1771 |
+
utilization as a percentage.
|
| 1772 |
+
|
| 1773 |
+
When *interval* is > 0.0 compares system CPU times elapsed before
|
| 1774 |
+
and after the interval (blocking).
|
| 1775 |
+
|
| 1776 |
+
When *interval* is 0.0 or None compares system CPU times elapsed
|
| 1777 |
+
since last call or module import, returning immediately (non
|
| 1778 |
+
blocking). That means the first time this is called it will
|
| 1779 |
+
return a meaningless 0.0 value which you should ignore.
|
| 1780 |
+
In this case is recommended for accuracy that this function be
|
| 1781 |
+
called with at least 0.1 seconds between calls.
|
| 1782 |
+
|
| 1783 |
+
When *percpu* is True returns a list of floats representing the
|
| 1784 |
+
utilization as a percentage for each CPU.
|
| 1785 |
+
First element of the list refers to first CPU, second element
|
| 1786 |
+
to second CPU and so on.
|
| 1787 |
+
The order of the list is consistent across calls.
|
| 1788 |
+
|
| 1789 |
+
Examples:
|
| 1790 |
+
|
| 1791 |
+
>>> # blocking, system-wide
|
| 1792 |
+
>>> psutil.cpu_percent(interval=1)
|
| 1793 |
+
2.0
|
| 1794 |
+
>>>
|
| 1795 |
+
>>> # blocking, per-cpu
|
| 1796 |
+
>>> psutil.cpu_percent(interval=1, percpu=True)
|
| 1797 |
+
[2.0, 1.0]
|
| 1798 |
+
>>>
|
| 1799 |
+
>>> # non-blocking (percentage since last call)
|
| 1800 |
+
>>> psutil.cpu_percent(interval=None)
|
| 1801 |
+
2.9
|
| 1802 |
+
>>>
|
| 1803 |
+
"""
|
| 1804 |
+
tid = threading.current_thread().ident
|
| 1805 |
+
blocking = interval is not None and interval > 0.0
|
| 1806 |
+
if interval is not None and interval < 0:
|
| 1807 |
+
msg = "interval is not positive (got %r)" % interval
|
| 1808 |
+
raise ValueError(msg)
|
| 1809 |
+
|
| 1810 |
+
def calculate(t1, t2):
|
| 1811 |
+
times_delta = _cpu_times_deltas(t1, t2)
|
| 1812 |
+
all_delta = _cpu_tot_time(times_delta)
|
| 1813 |
+
busy_delta = _cpu_busy_time(times_delta)
|
| 1814 |
+
|
| 1815 |
+
try:
|
| 1816 |
+
busy_perc = (busy_delta / all_delta) * 100
|
| 1817 |
+
except ZeroDivisionError:
|
| 1818 |
+
return 0.0
|
| 1819 |
+
else:
|
| 1820 |
+
return round(busy_perc, 1)
|
| 1821 |
+
|
| 1822 |
+
# system-wide usage
|
| 1823 |
+
if not percpu:
|
| 1824 |
+
if blocking:
|
| 1825 |
+
t1 = cpu_times()
|
| 1826 |
+
time.sleep(interval)
|
| 1827 |
+
else:
|
| 1828 |
+
t1 = _last_cpu_times.get(tid) or cpu_times()
|
| 1829 |
+
_last_cpu_times[tid] = cpu_times()
|
| 1830 |
+
return calculate(t1, _last_cpu_times[tid])
|
| 1831 |
+
# per-cpu usage
|
| 1832 |
+
else:
|
| 1833 |
+
ret = []
|
| 1834 |
+
if blocking:
|
| 1835 |
+
tot1 = cpu_times(percpu=True)
|
| 1836 |
+
time.sleep(interval)
|
| 1837 |
+
else:
|
| 1838 |
+
tot1 = _last_per_cpu_times.get(tid) or cpu_times(percpu=True)
|
| 1839 |
+
_last_per_cpu_times[tid] = cpu_times(percpu=True)
|
| 1840 |
+
for t1, t2 in zip(tot1, _last_per_cpu_times[tid]):
|
| 1841 |
+
ret.append(calculate(t1, t2))
|
| 1842 |
+
return ret
|
| 1843 |
+
|
| 1844 |
+
|
| 1845 |
+
# Use a separate dict for cpu_times_percent(), so it's independent from
|
| 1846 |
+
# cpu_percent() and they can both be used within the same program.
|
| 1847 |
+
_last_cpu_times_2 = _last_cpu_times.copy()
|
| 1848 |
+
_last_per_cpu_times_2 = _last_per_cpu_times.copy()
|
| 1849 |
+
|
| 1850 |
+
|
| 1851 |
+
def cpu_times_percent(interval=None, percpu=False):
|
| 1852 |
+
"""Same as cpu_percent() but provides utilization percentages
|
| 1853 |
+
for each specific CPU time as is returned by cpu_times().
|
| 1854 |
+
For instance, on Linux we'll get:
|
| 1855 |
+
|
| 1856 |
+
>>> cpu_times_percent()
|
| 1857 |
+
cpupercent(user=4.8, nice=0.0, system=4.8, idle=90.5, iowait=0.0,
|
| 1858 |
+
irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
|
| 1859 |
+
>>>
|
| 1860 |
+
|
| 1861 |
+
*interval* and *percpu* arguments have the same meaning as in
|
| 1862 |
+
cpu_percent().
|
| 1863 |
+
"""
|
| 1864 |
+
tid = threading.current_thread().ident
|
| 1865 |
+
blocking = interval is not None and interval > 0.0
|
| 1866 |
+
if interval is not None and interval < 0:
|
| 1867 |
+
msg = "interval is not positive (got %r)" % interval
|
| 1868 |
+
raise ValueError(msg)
|
| 1869 |
+
|
| 1870 |
+
def calculate(t1, t2):
|
| 1871 |
+
nums = []
|
| 1872 |
+
times_delta = _cpu_times_deltas(t1, t2)
|
| 1873 |
+
all_delta = _cpu_tot_time(times_delta)
|
| 1874 |
+
# "scale" is the value to multiply each delta with to get percentages.
|
| 1875 |
+
# We use "max" to avoid division by zero (if all_delta is 0, then all
|
| 1876 |
+
# fields are 0 so percentages will be 0 too. all_delta cannot be a
|
| 1877 |
+
# fraction because cpu times are integers)
|
| 1878 |
+
scale = 100.0 / max(1, all_delta)
|
| 1879 |
+
for field_delta in times_delta:
|
| 1880 |
+
field_perc = field_delta * scale
|
| 1881 |
+
field_perc = round(field_perc, 1)
|
| 1882 |
+
# make sure we don't return negative values or values over 100%
|
| 1883 |
+
field_perc = min(max(0.0, field_perc), 100.0)
|
| 1884 |
+
nums.append(field_perc)
|
| 1885 |
+
return _psplatform.scputimes(*nums)
|
| 1886 |
+
|
| 1887 |
+
# system-wide usage
|
| 1888 |
+
if not percpu:
|
| 1889 |
+
if blocking:
|
| 1890 |
+
t1 = cpu_times()
|
| 1891 |
+
time.sleep(interval)
|
| 1892 |
+
else:
|
| 1893 |
+
t1 = _last_cpu_times_2.get(tid) or cpu_times()
|
| 1894 |
+
_last_cpu_times_2[tid] = cpu_times()
|
| 1895 |
+
return calculate(t1, _last_cpu_times_2[tid])
|
| 1896 |
+
# per-cpu usage
|
| 1897 |
+
else:
|
| 1898 |
+
ret = []
|
| 1899 |
+
if blocking:
|
| 1900 |
+
tot1 = cpu_times(percpu=True)
|
| 1901 |
+
time.sleep(interval)
|
| 1902 |
+
else:
|
| 1903 |
+
tot1 = _last_per_cpu_times_2.get(tid) or cpu_times(percpu=True)
|
| 1904 |
+
_last_per_cpu_times_2[tid] = cpu_times(percpu=True)
|
| 1905 |
+
for t1, t2 in zip(tot1, _last_per_cpu_times_2[tid]):
|
| 1906 |
+
ret.append(calculate(t1, t2))
|
| 1907 |
+
return ret
|
| 1908 |
+
|
| 1909 |
+
|
| 1910 |
+
def cpu_stats():
|
| 1911 |
+
"""Return CPU statistics."""
|
| 1912 |
+
return _psplatform.cpu_stats()
|
| 1913 |
+
|
| 1914 |
+
|
| 1915 |
+
if hasattr(_psplatform, "cpu_freq"):
|
| 1916 |
+
|
| 1917 |
+
def cpu_freq(percpu=False):
|
| 1918 |
+
"""Return CPU frequency as a namedtuple including current,
|
| 1919 |
+
min and max frequency expressed in Mhz.
|
| 1920 |
+
|
| 1921 |
+
If *percpu* is True and the system supports per-cpu frequency
|
| 1922 |
+
retrieval (Linux only) a list of frequencies is returned for
|
| 1923 |
+
each CPU. If not a list with one element is returned.
|
| 1924 |
+
"""
|
| 1925 |
+
ret = _psplatform.cpu_freq()
|
| 1926 |
+
if percpu:
|
| 1927 |
+
return ret
|
| 1928 |
+
else:
|
| 1929 |
+
num_cpus = float(len(ret))
|
| 1930 |
+
if num_cpus == 0:
|
| 1931 |
+
return None
|
| 1932 |
+
elif num_cpus == 1:
|
| 1933 |
+
return ret[0]
|
| 1934 |
+
else:
|
| 1935 |
+
currs, mins, maxs = 0.0, 0.0, 0.0
|
| 1936 |
+
set_none = False
|
| 1937 |
+
for cpu in ret:
|
| 1938 |
+
currs += cpu.current
|
| 1939 |
+
# On Linux if /proc/cpuinfo is used min/max are set
|
| 1940 |
+
# to None.
|
| 1941 |
+
if LINUX and cpu.min is None:
|
| 1942 |
+
set_none = True
|
| 1943 |
+
continue
|
| 1944 |
+
mins += cpu.min
|
| 1945 |
+
maxs += cpu.max
|
| 1946 |
+
|
| 1947 |
+
current = currs / num_cpus
|
| 1948 |
+
|
| 1949 |
+
if set_none:
|
| 1950 |
+
min_ = max_ = None
|
| 1951 |
+
else:
|
| 1952 |
+
min_ = mins / num_cpus
|
| 1953 |
+
max_ = maxs / num_cpus
|
| 1954 |
+
|
| 1955 |
+
return _common.scpufreq(current, min_, max_)
|
| 1956 |
+
|
| 1957 |
+
__all__.append("cpu_freq")
|
| 1958 |
+
|
| 1959 |
+
|
| 1960 |
+
if hasattr(os, "getloadavg") or hasattr(_psplatform, "getloadavg"):
|
| 1961 |
+
# Perform this hasattr check once on import time to either use the
|
| 1962 |
+
# platform based code or proxy straight from the os module.
|
| 1963 |
+
if hasattr(os, "getloadavg"):
|
| 1964 |
+
getloadavg = os.getloadavg
|
| 1965 |
+
else:
|
| 1966 |
+
getloadavg = _psplatform.getloadavg
|
| 1967 |
+
|
| 1968 |
+
__all__.append("getloadavg")
|
| 1969 |
+
|
| 1970 |
+
|
| 1971 |
+
# =====================================================================
|
| 1972 |
+
# --- system memory related functions
|
| 1973 |
+
# =====================================================================
|
| 1974 |
+
|
| 1975 |
+
|
| 1976 |
+
def virtual_memory():
|
| 1977 |
+
"""Return statistics about system memory usage as a namedtuple
|
| 1978 |
+
including the following fields, expressed in bytes:
|
| 1979 |
+
|
| 1980 |
+
- total:
|
| 1981 |
+
total physical memory available.
|
| 1982 |
+
|
| 1983 |
+
- available:
|
| 1984 |
+
the memory that can be given instantly to processes without the
|
| 1985 |
+
system going into swap.
|
| 1986 |
+
This is calculated by summing different memory values depending
|
| 1987 |
+
on the platform and it is supposed to be used to monitor actual
|
| 1988 |
+
memory usage in a cross platform fashion.
|
| 1989 |
+
|
| 1990 |
+
- percent:
|
| 1991 |
+
the percentage usage calculated as (total - available) / total * 100
|
| 1992 |
+
|
| 1993 |
+
- used:
|
| 1994 |
+
memory used, calculated differently depending on the platform and
|
| 1995 |
+
designed for informational purposes only:
|
| 1996 |
+
macOS: active + wired
|
| 1997 |
+
BSD: active + wired + cached
|
| 1998 |
+
Linux: total - free
|
| 1999 |
+
|
| 2000 |
+
- free:
|
| 2001 |
+
memory not being used at all (zeroed) that is readily available;
|
| 2002 |
+
note that this doesn't reflect the actual memory available
|
| 2003 |
+
(use 'available' instead)
|
| 2004 |
+
|
| 2005 |
+
Platform-specific fields:
|
| 2006 |
+
|
| 2007 |
+
- active (UNIX):
|
| 2008 |
+
memory currently in use or very recently used, and so it is in RAM.
|
| 2009 |
+
|
| 2010 |
+
- inactive (UNIX):
|
| 2011 |
+
memory that is marked as not used.
|
| 2012 |
+
|
| 2013 |
+
- buffers (BSD, Linux):
|
| 2014 |
+
cache for things like file system metadata.
|
| 2015 |
+
|
| 2016 |
+
- cached (BSD, macOS):
|
| 2017 |
+
cache for various things.
|
| 2018 |
+
|
| 2019 |
+
- wired (macOS, BSD):
|
| 2020 |
+
memory that is marked to always stay in RAM. It is never moved to disk.
|
| 2021 |
+
|
| 2022 |
+
- shared (BSD):
|
| 2023 |
+
memory that may be simultaneously accessed by multiple processes.
|
| 2024 |
+
|
| 2025 |
+
The sum of 'used' and 'available' does not necessarily equal total.
|
| 2026 |
+
On Windows 'available' and 'free' are the same.
|
| 2027 |
+
"""
|
| 2028 |
+
global _TOTAL_PHYMEM
|
| 2029 |
+
ret = _psplatform.virtual_memory()
|
| 2030 |
+
# cached for later use in Process.memory_percent()
|
| 2031 |
+
_TOTAL_PHYMEM = ret.total
|
| 2032 |
+
return ret
|
| 2033 |
+
|
| 2034 |
+
|
| 2035 |
+
def swap_memory():
|
| 2036 |
+
"""Return system swap memory statistics as a namedtuple including
|
| 2037 |
+
the following fields:
|
| 2038 |
+
|
| 2039 |
+
- total: total swap memory in bytes
|
| 2040 |
+
- used: used swap memory in bytes
|
| 2041 |
+
- free: free swap memory in bytes
|
| 2042 |
+
- percent: the percentage usage
|
| 2043 |
+
- sin: no. of bytes the system has swapped in from disk (cumulative)
|
| 2044 |
+
- sout: no. of bytes the system has swapped out from disk (cumulative)
|
| 2045 |
+
|
| 2046 |
+
'sin' and 'sout' on Windows are meaningless and always set to 0.
|
| 2047 |
+
"""
|
| 2048 |
+
return _psplatform.swap_memory()
|
| 2049 |
+
|
| 2050 |
+
|
| 2051 |
+
# =====================================================================
|
| 2052 |
+
# --- disks/partitions related functions
|
| 2053 |
+
# =====================================================================
|
| 2054 |
+
|
| 2055 |
+
|
| 2056 |
+
def disk_usage(path):
|
| 2057 |
+
"""Return disk usage statistics about the given *path* as a
|
| 2058 |
+
namedtuple including total, used and free space expressed in bytes
|
| 2059 |
+
plus the percentage usage.
|
| 2060 |
+
"""
|
| 2061 |
+
return _psplatform.disk_usage(path)
|
| 2062 |
+
|
| 2063 |
+
|
| 2064 |
+
def disk_partitions(all=False):
|
| 2065 |
+
"""Return mounted partitions as a list of
|
| 2066 |
+
(device, mountpoint, fstype, opts) namedtuple.
|
| 2067 |
+
'opts' field is a raw string separated by commas indicating mount
|
| 2068 |
+
options which may vary depending on the platform.
|
| 2069 |
+
|
| 2070 |
+
If *all* parameter is False return physical devices only and ignore
|
| 2071 |
+
all others.
|
| 2072 |
+
"""
|
| 2073 |
+
return _psplatform.disk_partitions(all)
|
| 2074 |
+
|
| 2075 |
+
|
| 2076 |
+
def disk_io_counters(perdisk=False, nowrap=True):
|
| 2077 |
+
"""Return system disk I/O statistics as a namedtuple including
|
| 2078 |
+
the following fields:
|
| 2079 |
+
|
| 2080 |
+
- read_count: number of reads
|
| 2081 |
+
- write_count: number of writes
|
| 2082 |
+
- read_bytes: number of bytes read
|
| 2083 |
+
- write_bytes: number of bytes written
|
| 2084 |
+
- read_time: time spent reading from disk (in ms)
|
| 2085 |
+
- write_time: time spent writing to disk (in ms)
|
| 2086 |
+
|
| 2087 |
+
Platform specific:
|
| 2088 |
+
|
| 2089 |
+
- busy_time: (Linux, FreeBSD) time spent doing actual I/Os (in ms)
|
| 2090 |
+
- read_merged_count (Linux): number of merged reads
|
| 2091 |
+
- write_merged_count (Linux): number of merged writes
|
| 2092 |
+
|
| 2093 |
+
If *perdisk* is True return the same information for every
|
| 2094 |
+
physical disk installed on the system as a dictionary
|
| 2095 |
+
with partition names as the keys and the namedtuple
|
| 2096 |
+
described above as the values.
|
| 2097 |
+
|
| 2098 |
+
If *nowrap* is True it detects and adjust the numbers which overflow
|
| 2099 |
+
and wrap (restart from 0) and add "old value" to "new value" so that
|
| 2100 |
+
the returned numbers will always be increasing or remain the same,
|
| 2101 |
+
but never decrease.
|
| 2102 |
+
"disk_io_counters.cache_clear()" can be used to invalidate the
|
| 2103 |
+
cache.
|
| 2104 |
+
|
| 2105 |
+
On recent Windows versions 'diskperf -y' command may need to be
|
| 2106 |
+
executed first otherwise this function won't find any disk.
|
| 2107 |
+
"""
|
| 2108 |
+
kwargs = dict(perdisk=perdisk) if LINUX else {}
|
| 2109 |
+
rawdict = _psplatform.disk_io_counters(**kwargs)
|
| 2110 |
+
if not rawdict:
|
| 2111 |
+
return {} if perdisk else None
|
| 2112 |
+
if nowrap:
|
| 2113 |
+
rawdict = _wrap_numbers(rawdict, 'psutil.disk_io_counters')
|
| 2114 |
+
nt = getattr(_psplatform, "sdiskio", _common.sdiskio)
|
| 2115 |
+
if perdisk:
|
| 2116 |
+
for disk, fields in rawdict.items():
|
| 2117 |
+
rawdict[disk] = nt(*fields)
|
| 2118 |
+
return rawdict
|
| 2119 |
+
else:
|
| 2120 |
+
return nt(*(sum(x) for x in zip(*rawdict.values())))
|
| 2121 |
+
|
| 2122 |
+
|
| 2123 |
+
disk_io_counters.cache_clear = functools.partial(
|
| 2124 |
+
_wrap_numbers.cache_clear, 'psutil.disk_io_counters'
|
| 2125 |
+
)
|
| 2126 |
+
disk_io_counters.cache_clear.__doc__ = "Clears nowrap argument cache"
|
| 2127 |
+
|
| 2128 |
+
|
| 2129 |
+
# =====================================================================
|
| 2130 |
+
# --- network related functions
|
| 2131 |
+
# =====================================================================
|
| 2132 |
+
|
| 2133 |
+
|
| 2134 |
+
def net_io_counters(pernic=False, nowrap=True):
|
| 2135 |
+
"""Return network I/O statistics as a namedtuple including
|
| 2136 |
+
the following fields:
|
| 2137 |
+
|
| 2138 |
+
- bytes_sent: number of bytes sent
|
| 2139 |
+
- bytes_recv: number of bytes received
|
| 2140 |
+
- packets_sent: number of packets sent
|
| 2141 |
+
- packets_recv: number of packets received
|
| 2142 |
+
- errin: total number of errors while receiving
|
| 2143 |
+
- errout: total number of errors while sending
|
| 2144 |
+
- dropin: total number of incoming packets which were dropped
|
| 2145 |
+
- dropout: total number of outgoing packets which were dropped
|
| 2146 |
+
(always 0 on macOS and BSD)
|
| 2147 |
+
|
| 2148 |
+
If *pernic* is True return the same information for every
|
| 2149 |
+
network interface installed on the system as a dictionary
|
| 2150 |
+
with network interface names as the keys and the namedtuple
|
| 2151 |
+
described above as the values.
|
| 2152 |
+
|
| 2153 |
+
If *nowrap* is True it detects and adjust the numbers which overflow
|
| 2154 |
+
and wrap (restart from 0) and add "old value" to "new value" so that
|
| 2155 |
+
the returned numbers will always be increasing or remain the same,
|
| 2156 |
+
but never decrease.
|
| 2157 |
+
"net_io_counters.cache_clear()" can be used to invalidate the
|
| 2158 |
+
cache.
|
| 2159 |
+
"""
|
| 2160 |
+
rawdict = _psplatform.net_io_counters()
|
| 2161 |
+
if not rawdict:
|
| 2162 |
+
return {} if pernic else None
|
| 2163 |
+
if nowrap:
|
| 2164 |
+
rawdict = _wrap_numbers(rawdict, 'psutil.net_io_counters')
|
| 2165 |
+
if pernic:
|
| 2166 |
+
for nic, fields in rawdict.items():
|
| 2167 |
+
rawdict[nic] = _common.snetio(*fields)
|
| 2168 |
+
return rawdict
|
| 2169 |
+
else:
|
| 2170 |
+
return _common.snetio(*[sum(x) for x in zip(*rawdict.values())])
|
| 2171 |
+
|
| 2172 |
+
|
| 2173 |
+
net_io_counters.cache_clear = functools.partial(
|
| 2174 |
+
_wrap_numbers.cache_clear, 'psutil.net_io_counters'
|
| 2175 |
+
)
|
| 2176 |
+
net_io_counters.cache_clear.__doc__ = "Clears nowrap argument cache"
|
| 2177 |
+
|
| 2178 |
+
|
| 2179 |
+
def net_connections(kind='inet'):
|
| 2180 |
+
"""Return system-wide socket connections as a list of
|
| 2181 |
+
(fd, family, type, laddr, raddr, status, pid) namedtuples.
|
| 2182 |
+
In case of limited privileges 'fd' and 'pid' may be set to -1
|
| 2183 |
+
and None respectively.
|
| 2184 |
+
The *kind* parameter filters for connections that fit the
|
| 2185 |
+
following criteria:
|
| 2186 |
+
|
| 2187 |
+
+------------+----------------------------------------------------+
|
| 2188 |
+
| Kind Value | Connections using |
|
| 2189 |
+
+------------+----------------------------------------------------+
|
| 2190 |
+
| inet | IPv4 and IPv6 |
|
| 2191 |
+
| inet4 | IPv4 |
|
| 2192 |
+
| inet6 | IPv6 |
|
| 2193 |
+
| tcp | TCP |
|
| 2194 |
+
| tcp4 | TCP over IPv4 |
|
| 2195 |
+
| tcp6 | TCP over IPv6 |
|
| 2196 |
+
| udp | UDP |
|
| 2197 |
+
| udp4 | UDP over IPv4 |
|
| 2198 |
+
| udp6 | UDP over IPv6 |
|
| 2199 |
+
| unix | UNIX socket (both UDP and TCP protocols) |
|
| 2200 |
+
| all | the sum of all the possible families and protocols |
|
| 2201 |
+
+------------+----------------------------------------------------+
|
| 2202 |
+
|
| 2203 |
+
On macOS this function requires root privileges.
|
| 2204 |
+
"""
|
| 2205 |
+
return _psplatform.net_connections(kind)
|
| 2206 |
+
|
| 2207 |
+
|
| 2208 |
+
def net_if_addrs():
|
| 2209 |
+
"""Return the addresses associated to each NIC (network interface
|
| 2210 |
+
card) installed on the system as a dictionary whose keys are the
|
| 2211 |
+
NIC names and value is a list of namedtuples for each address
|
| 2212 |
+
assigned to the NIC. Each namedtuple includes 5 fields:
|
| 2213 |
+
|
| 2214 |
+
- family: can be either socket.AF_INET, socket.AF_INET6 or
|
| 2215 |
+
psutil.AF_LINK, which refers to a MAC address.
|
| 2216 |
+
- address: is the primary address and it is always set.
|
| 2217 |
+
- netmask: and 'broadcast' and 'ptp' may be None.
|
| 2218 |
+
- ptp: stands for "point to point" and references the
|
| 2219 |
+
destination address on a point to point interface
|
| 2220 |
+
(typically a VPN).
|
| 2221 |
+
- broadcast: and *ptp* are mutually exclusive.
|
| 2222 |
+
|
| 2223 |
+
Note: you can have more than one address of the same family
|
| 2224 |
+
associated with each interface.
|
| 2225 |
+
"""
|
| 2226 |
+
has_enums = _PY3
|
| 2227 |
+
if has_enums:
|
| 2228 |
+
import socket
|
| 2229 |
+
rawlist = _psplatform.net_if_addrs()
|
| 2230 |
+
rawlist.sort(key=lambda x: x[1]) # sort by family
|
| 2231 |
+
ret = collections.defaultdict(list)
|
| 2232 |
+
for name, fam, addr, mask, broadcast, ptp in rawlist:
|
| 2233 |
+
if has_enums:
|
| 2234 |
+
try:
|
| 2235 |
+
fam = socket.AddressFamily(fam)
|
| 2236 |
+
except ValueError:
|
| 2237 |
+
if WINDOWS and fam == -1:
|
| 2238 |
+
fam = _psplatform.AF_LINK
|
| 2239 |
+
elif (
|
| 2240 |
+
hasattr(_psplatform, "AF_LINK")
|
| 2241 |
+
and fam == _psplatform.AF_LINK
|
| 2242 |
+
):
|
| 2243 |
+
# Linux defines AF_LINK as an alias for AF_PACKET.
|
| 2244 |
+
# We re-set the family here so that repr(family)
|
| 2245 |
+
# will show AF_LINK rather than AF_PACKET
|
| 2246 |
+
fam = _psplatform.AF_LINK
|
| 2247 |
+
if fam == _psplatform.AF_LINK:
|
| 2248 |
+
# The underlying C function may return an incomplete MAC
|
| 2249 |
+
# address in which case we fill it with null bytes, see:
|
| 2250 |
+
# https://github.com/giampaolo/psutil/issues/786
|
| 2251 |
+
separator = ":" if POSIX else "-"
|
| 2252 |
+
while addr.count(separator) < 5:
|
| 2253 |
+
addr += "%s00" % separator
|
| 2254 |
+
ret[name].append(_common.snicaddr(fam, addr, mask, broadcast, ptp))
|
| 2255 |
+
return dict(ret)
|
| 2256 |
+
|
| 2257 |
+
|
| 2258 |
+
def net_if_stats():
|
| 2259 |
+
"""Return information about each NIC (network interface card)
|
| 2260 |
+
installed on the system as a dictionary whose keys are the
|
| 2261 |
+
NIC names and value is a namedtuple with the following fields:
|
| 2262 |
+
|
| 2263 |
+
- isup: whether the interface is up (bool)
|
| 2264 |
+
- duplex: can be either NIC_DUPLEX_FULL, NIC_DUPLEX_HALF or
|
| 2265 |
+
NIC_DUPLEX_UNKNOWN
|
| 2266 |
+
- speed: the NIC speed expressed in mega bits (MB); if it can't
|
| 2267 |
+
be determined (e.g. 'localhost') it will be set to 0.
|
| 2268 |
+
- mtu: the maximum transmission unit expressed in bytes.
|
| 2269 |
+
"""
|
| 2270 |
+
return _psplatform.net_if_stats()
|
| 2271 |
+
|
| 2272 |
+
|
| 2273 |
+
# =====================================================================
|
| 2274 |
+
# --- sensors
|
| 2275 |
+
# =====================================================================
|
| 2276 |
+
|
| 2277 |
+
|
| 2278 |
+
# Linux, macOS
|
| 2279 |
+
if hasattr(_psplatform, "sensors_temperatures"):
|
| 2280 |
+
|
| 2281 |
+
def sensors_temperatures(fahrenheit=False):
|
| 2282 |
+
"""Return hardware temperatures. Each entry is a namedtuple
|
| 2283 |
+
representing a certain hardware sensor (it may be a CPU, an
|
| 2284 |
+
hard disk or something else, depending on the OS and its
|
| 2285 |
+
configuration).
|
| 2286 |
+
All temperatures are expressed in celsius unless *fahrenheit*
|
| 2287 |
+
is set to True.
|
| 2288 |
+
"""
|
| 2289 |
+
|
| 2290 |
+
def convert(n):
|
| 2291 |
+
if n is not None:
|
| 2292 |
+
return (float(n) * 9 / 5) + 32 if fahrenheit else n
|
| 2293 |
+
|
| 2294 |
+
ret = collections.defaultdict(list)
|
| 2295 |
+
rawdict = _psplatform.sensors_temperatures()
|
| 2296 |
+
|
| 2297 |
+
for name, values in rawdict.items():
|
| 2298 |
+
while values:
|
| 2299 |
+
label, current, high, critical = values.pop(0)
|
| 2300 |
+
current = convert(current)
|
| 2301 |
+
high = convert(high)
|
| 2302 |
+
critical = convert(critical)
|
| 2303 |
+
|
| 2304 |
+
if high and not critical:
|
| 2305 |
+
critical = high
|
| 2306 |
+
elif critical and not high:
|
| 2307 |
+
high = critical
|
| 2308 |
+
|
| 2309 |
+
ret[name].append(
|
| 2310 |
+
_common.shwtemp(label, current, high, critical)
|
| 2311 |
+
)
|
| 2312 |
+
|
| 2313 |
+
return dict(ret)
|
| 2314 |
+
|
| 2315 |
+
__all__.append("sensors_temperatures")
|
| 2316 |
+
|
| 2317 |
+
|
| 2318 |
+
# Linux
|
| 2319 |
+
if hasattr(_psplatform, "sensors_fans"):
|
| 2320 |
+
|
| 2321 |
+
def sensors_fans():
|
| 2322 |
+
"""Return fans speed. Each entry is a namedtuple
|
| 2323 |
+
representing a certain hardware sensor.
|
| 2324 |
+
All speed are expressed in RPM (rounds per minute).
|
| 2325 |
+
"""
|
| 2326 |
+
return _psplatform.sensors_fans()
|
| 2327 |
+
|
| 2328 |
+
__all__.append("sensors_fans")
|
| 2329 |
+
|
| 2330 |
+
|
| 2331 |
+
# Linux, Windows, FreeBSD, macOS
|
| 2332 |
+
if hasattr(_psplatform, "sensors_battery"):
|
| 2333 |
+
|
| 2334 |
+
def sensors_battery():
|
| 2335 |
+
"""Return battery information. If no battery is installed
|
| 2336 |
+
returns None.
|
| 2337 |
+
|
| 2338 |
+
- percent: battery power left as a percentage.
|
| 2339 |
+
- secsleft: a rough approximation of how many seconds are left
|
| 2340 |
+
before the battery runs out of power. May be
|
| 2341 |
+
POWER_TIME_UNLIMITED or POWER_TIME_UNLIMITED.
|
| 2342 |
+
- power_plugged: True if the AC power cable is connected.
|
| 2343 |
+
"""
|
| 2344 |
+
return _psplatform.sensors_battery()
|
| 2345 |
+
|
| 2346 |
+
__all__.append("sensors_battery")
|
| 2347 |
+
|
| 2348 |
+
|
| 2349 |
+
# =====================================================================
|
| 2350 |
+
# --- other system related functions
|
| 2351 |
+
# =====================================================================
|
| 2352 |
+
|
| 2353 |
+
|
| 2354 |
+
def boot_time():
|
| 2355 |
+
"""Return the system boot time expressed in seconds since the epoch."""
|
| 2356 |
+
# Note: we are not caching this because it is subject to
|
| 2357 |
+
# system clock updates.
|
| 2358 |
+
return _psplatform.boot_time()
|
| 2359 |
+
|
| 2360 |
+
|
| 2361 |
+
def users():
|
| 2362 |
+
"""Return users currently connected on the system as a list of
|
| 2363 |
+
namedtuples including the following fields.
|
| 2364 |
+
|
| 2365 |
+
- user: the name of the user
|
| 2366 |
+
- terminal: the tty or pseudo-tty associated with the user, if any.
|
| 2367 |
+
- host: the host name associated with the entry, if any.
|
| 2368 |
+
- started: the creation time as a floating point number expressed in
|
| 2369 |
+
seconds since the epoch.
|
| 2370 |
+
"""
|
| 2371 |
+
return _psplatform.users()
|
| 2372 |
+
|
| 2373 |
+
|
| 2374 |
+
# =====================================================================
|
| 2375 |
+
# --- Windows services
|
| 2376 |
+
# =====================================================================
|
| 2377 |
+
|
| 2378 |
+
|
| 2379 |
+
if WINDOWS:
|
| 2380 |
+
|
| 2381 |
+
def win_service_iter():
|
| 2382 |
+
"""Return a generator yielding a WindowsService instance for all
|
| 2383 |
+
Windows services installed.
|
| 2384 |
+
"""
|
| 2385 |
+
return _psplatform.win_service_iter()
|
| 2386 |
+
|
| 2387 |
+
def win_service_get(name):
|
| 2388 |
+
"""Get a Windows service by *name*.
|
| 2389 |
+
Raise NoSuchProcess if no service with such name exists.
|
| 2390 |
+
"""
|
| 2391 |
+
return _psplatform.win_service_get(name)
|
| 2392 |
+
|
| 2393 |
+
|
| 2394 |
+
# =====================================================================
|
| 2395 |
+
|
| 2396 |
+
|
| 2397 |
+
def _set_debug(value):
|
| 2398 |
+
"""Enable or disable PSUTIL_DEBUG option, which prints debugging
|
| 2399 |
+
messages to stderr.
|
| 2400 |
+
"""
|
| 2401 |
+
import psutil._common
|
| 2402 |
+
|
| 2403 |
+
psutil._common.PSUTIL_DEBUG = bool(value)
|
| 2404 |
+
_psplatform.cext.set_debug(bool(value))
|
| 2405 |
+
|
| 2406 |
+
|
| 2407 |
+
def test(): # pragma: no cover
|
| 2408 |
+
from ._common import bytes2human
|
| 2409 |
+
from ._compat import get_terminal_size
|
| 2410 |
+
|
| 2411 |
+
today_day = datetime.date.today()
|
| 2412 |
+
# fmt: off
|
| 2413 |
+
templ = "%-10s %5s %5s %7s %7s %5s %6s %6s %6s %s"
|
| 2414 |
+
attrs = ['pid', 'memory_percent', 'name', 'cmdline', 'cpu_times',
|
| 2415 |
+
'create_time', 'memory_info', 'status', 'nice', 'username']
|
| 2416 |
+
print(templ % ("USER", "PID", "%MEM", "VSZ", "RSS", "NICE", # NOQA
|
| 2417 |
+
"STATUS", "START", "TIME", "CMDLINE"))
|
| 2418 |
+
# fmt: on
|
| 2419 |
+
for p in process_iter(attrs, ad_value=None):
|
| 2420 |
+
if p.info['create_time']:
|
| 2421 |
+
ctime = datetime.datetime.fromtimestamp(p.info['create_time'])
|
| 2422 |
+
if ctime.date() == today_day:
|
| 2423 |
+
ctime = ctime.strftime("%H:%M")
|
| 2424 |
+
else:
|
| 2425 |
+
ctime = ctime.strftime("%b%d")
|
| 2426 |
+
else:
|
| 2427 |
+
ctime = ''
|
| 2428 |
+
if p.info['cpu_times']:
|
| 2429 |
+
cputime = time.strftime(
|
| 2430 |
+
"%M:%S", time.localtime(sum(p.info['cpu_times']))
|
| 2431 |
+
)
|
| 2432 |
+
else:
|
| 2433 |
+
cputime = ''
|
| 2434 |
+
|
| 2435 |
+
user = p.info['username'] or ''
|
| 2436 |
+
if not user and POSIX:
|
| 2437 |
+
try:
|
| 2438 |
+
user = p.uids()[0]
|
| 2439 |
+
except Error:
|
| 2440 |
+
pass
|
| 2441 |
+
if user and WINDOWS and '\\' in user:
|
| 2442 |
+
user = user.split('\\')[1]
|
| 2443 |
+
user = user[:9]
|
| 2444 |
+
vms = (
|
| 2445 |
+
bytes2human(p.info['memory_info'].vms)
|
| 2446 |
+
if p.info['memory_info'] is not None
|
| 2447 |
+
else ''
|
| 2448 |
+
)
|
| 2449 |
+
rss = (
|
| 2450 |
+
bytes2human(p.info['memory_info'].rss)
|
| 2451 |
+
if p.info['memory_info'] is not None
|
| 2452 |
+
else ''
|
| 2453 |
+
)
|
| 2454 |
+
memp = (
|
| 2455 |
+
round(p.info['memory_percent'], 1)
|
| 2456 |
+
if p.info['memory_percent'] is not None
|
| 2457 |
+
else ''
|
| 2458 |
+
)
|
| 2459 |
+
nice = int(p.info['nice']) if p.info['nice'] else ''
|
| 2460 |
+
if p.info['cmdline']:
|
| 2461 |
+
cmdline = ' '.join(p.info['cmdline'])
|
| 2462 |
+
else:
|
| 2463 |
+
cmdline = p.info['name']
|
| 2464 |
+
status = p.info['status'][:5] if p.info['status'] else ''
|
| 2465 |
+
|
| 2466 |
+
line = templ % (
|
| 2467 |
+
user[:10],
|
| 2468 |
+
p.info['pid'],
|
| 2469 |
+
memp,
|
| 2470 |
+
vms,
|
| 2471 |
+
rss,
|
| 2472 |
+
nice,
|
| 2473 |
+
status,
|
| 2474 |
+
ctime,
|
| 2475 |
+
cputime,
|
| 2476 |
+
cmdline,
|
| 2477 |
+
)
|
| 2478 |
+
print(line[: get_terminal_size()[0]]) # NOQA
|
| 2479 |
+
|
| 2480 |
+
|
| 2481 |
+
del memoize_when_activated, division
|
| 2482 |
+
if sys.version_info[0] < 3:
|
| 2483 |
+
del num, x # noqa
|
| 2484 |
+
|
| 2485 |
+
if __name__ == "__main__":
|
| 2486 |
+
test()
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (64.6 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_common.cpython-310.pyc
ADDED
|
Binary file (23.1 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_compat.cpython-310.pyc
ADDED
|
Binary file (11.7 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_psaix.cpython-310.pyc
ADDED
|
Binary file (15.1 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_psbsd.cpython-310.pyc
ADDED
|
Binary file (20.9 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_pslinux.cpython-310.pyc
ADDED
|
Binary file (53.6 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_psosx.cpython-310.pyc
ADDED
|
Binary file (13.4 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_psposix.cpython-310.pyc
ADDED
|
Binary file (4.62 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_pssunos.cpython-310.pyc
ADDED
|
Binary file (18.1 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/__pycache__/_pswindows.cpython-310.pyc
ADDED
|
Binary file (29.3 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/_psbsd.py
ADDED
|
@@ -0,0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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
|
| 2 |
+
# Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
# found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
"""FreeBSD, OpenBSD and NetBSD platforms implementation."""
|
| 6 |
+
|
| 7 |
+
import contextlib
|
| 8 |
+
import errno
|
| 9 |
+
import functools
|
| 10 |
+
import os
|
| 11 |
+
from collections import defaultdict
|
| 12 |
+
from collections import namedtuple
|
| 13 |
+
from xml.etree import ElementTree # noqa ICN001
|
| 14 |
+
|
| 15 |
+
from . import _common
|
| 16 |
+
from . import _psposix
|
| 17 |
+
from . import _psutil_bsd as cext
|
| 18 |
+
from . import _psutil_posix as cext_posix
|
| 19 |
+
from ._common import FREEBSD
|
| 20 |
+
from ._common import NETBSD
|
| 21 |
+
from ._common import OPENBSD
|
| 22 |
+
from ._common import AccessDenied
|
| 23 |
+
from ._common import NoSuchProcess
|
| 24 |
+
from ._common import ZombieProcess
|
| 25 |
+
from ._common import conn_tmap
|
| 26 |
+
from ._common import conn_to_ntuple
|
| 27 |
+
from ._common import debug
|
| 28 |
+
from ._common import memoize
|
| 29 |
+
from ._common import memoize_when_activated
|
| 30 |
+
from ._common import usage_percent
|
| 31 |
+
from ._compat import FileNotFoundError
|
| 32 |
+
from ._compat import PermissionError
|
| 33 |
+
from ._compat import ProcessLookupError
|
| 34 |
+
from ._compat import which
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
__extra__all__ = []
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# =====================================================================
|
| 41 |
+
# --- globals
|
| 42 |
+
# =====================================================================
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
if FREEBSD:
|
| 46 |
+
PROC_STATUSES = {
|
| 47 |
+
cext.SIDL: _common.STATUS_IDLE,
|
| 48 |
+
cext.SRUN: _common.STATUS_RUNNING,
|
| 49 |
+
cext.SSLEEP: _common.STATUS_SLEEPING,
|
| 50 |
+
cext.SSTOP: _common.STATUS_STOPPED,
|
| 51 |
+
cext.SZOMB: _common.STATUS_ZOMBIE,
|
| 52 |
+
cext.SWAIT: _common.STATUS_WAITING,
|
| 53 |
+
cext.SLOCK: _common.STATUS_LOCKED,
|
| 54 |
+
}
|
| 55 |
+
elif OPENBSD:
|
| 56 |
+
PROC_STATUSES = {
|
| 57 |
+
cext.SIDL: _common.STATUS_IDLE,
|
| 58 |
+
cext.SSLEEP: _common.STATUS_SLEEPING,
|
| 59 |
+
cext.SSTOP: _common.STATUS_STOPPED,
|
| 60 |
+
# According to /usr/include/sys/proc.h SZOMB is unused.
|
| 61 |
+
# test_zombie_process() shows that SDEAD is the right
|
| 62 |
+
# equivalent. Also it appears there's no equivalent of
|
| 63 |
+
# psutil.STATUS_DEAD. SDEAD really means STATUS_ZOMBIE.
|
| 64 |
+
# cext.SZOMB: _common.STATUS_ZOMBIE,
|
| 65 |
+
cext.SDEAD: _common.STATUS_ZOMBIE,
|
| 66 |
+
cext.SZOMB: _common.STATUS_ZOMBIE,
|
| 67 |
+
# From http://www.eecs.harvard.edu/~margo/cs161/videos/proc.h.txt
|
| 68 |
+
# OpenBSD has SRUN and SONPROC: SRUN indicates that a process
|
| 69 |
+
# is runnable but *not* yet running, i.e. is on a run queue.
|
| 70 |
+
# SONPROC indicates that the process is actually executing on
|
| 71 |
+
# a CPU, i.e. it is no longer on a run queue.
|
| 72 |
+
# As such we'll map SRUN to STATUS_WAKING and SONPROC to
|
| 73 |
+
# STATUS_RUNNING
|
| 74 |
+
cext.SRUN: _common.STATUS_WAKING,
|
| 75 |
+
cext.SONPROC: _common.STATUS_RUNNING,
|
| 76 |
+
}
|
| 77 |
+
elif NETBSD:
|
| 78 |
+
PROC_STATUSES = {
|
| 79 |
+
cext.SIDL: _common.STATUS_IDLE,
|
| 80 |
+
cext.SSLEEP: _common.STATUS_SLEEPING,
|
| 81 |
+
cext.SSTOP: _common.STATUS_STOPPED,
|
| 82 |
+
cext.SZOMB: _common.STATUS_ZOMBIE,
|
| 83 |
+
cext.SRUN: _common.STATUS_WAKING,
|
| 84 |
+
cext.SONPROC: _common.STATUS_RUNNING,
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
TCP_STATUSES = {
|
| 88 |
+
cext.TCPS_ESTABLISHED: _common.CONN_ESTABLISHED,
|
| 89 |
+
cext.TCPS_SYN_SENT: _common.CONN_SYN_SENT,
|
| 90 |
+
cext.TCPS_SYN_RECEIVED: _common.CONN_SYN_RECV,
|
| 91 |
+
cext.TCPS_FIN_WAIT_1: _common.CONN_FIN_WAIT1,
|
| 92 |
+
cext.TCPS_FIN_WAIT_2: _common.CONN_FIN_WAIT2,
|
| 93 |
+
cext.TCPS_TIME_WAIT: _common.CONN_TIME_WAIT,
|
| 94 |
+
cext.TCPS_CLOSED: _common.CONN_CLOSE,
|
| 95 |
+
cext.TCPS_CLOSE_WAIT: _common.CONN_CLOSE_WAIT,
|
| 96 |
+
cext.TCPS_LAST_ACK: _common.CONN_LAST_ACK,
|
| 97 |
+
cext.TCPS_LISTEN: _common.CONN_LISTEN,
|
| 98 |
+
cext.TCPS_CLOSING: _common.CONN_CLOSING,
|
| 99 |
+
cext.PSUTIL_CONN_NONE: _common.CONN_NONE,
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
PAGESIZE = cext_posix.getpagesize()
|
| 103 |
+
AF_LINK = cext_posix.AF_LINK
|
| 104 |
+
|
| 105 |
+
HAS_PER_CPU_TIMES = hasattr(cext, "per_cpu_times")
|
| 106 |
+
HAS_PROC_NUM_THREADS = hasattr(cext, "proc_num_threads")
|
| 107 |
+
HAS_PROC_OPEN_FILES = hasattr(cext, 'proc_open_files')
|
| 108 |
+
HAS_PROC_NUM_FDS = hasattr(cext, 'proc_num_fds')
|
| 109 |
+
|
| 110 |
+
kinfo_proc_map = dict(
|
| 111 |
+
ppid=0,
|
| 112 |
+
status=1,
|
| 113 |
+
real_uid=2,
|
| 114 |
+
effective_uid=3,
|
| 115 |
+
saved_uid=4,
|
| 116 |
+
real_gid=5,
|
| 117 |
+
effective_gid=6,
|
| 118 |
+
saved_gid=7,
|
| 119 |
+
ttynr=8,
|
| 120 |
+
create_time=9,
|
| 121 |
+
ctx_switches_vol=10,
|
| 122 |
+
ctx_switches_unvol=11,
|
| 123 |
+
read_io_count=12,
|
| 124 |
+
write_io_count=13,
|
| 125 |
+
user_time=14,
|
| 126 |
+
sys_time=15,
|
| 127 |
+
ch_user_time=16,
|
| 128 |
+
ch_sys_time=17,
|
| 129 |
+
rss=18,
|
| 130 |
+
vms=19,
|
| 131 |
+
memtext=20,
|
| 132 |
+
memdata=21,
|
| 133 |
+
memstack=22,
|
| 134 |
+
cpunum=23,
|
| 135 |
+
name=24,
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
# =====================================================================
|
| 140 |
+
# --- named tuples
|
| 141 |
+
# =====================================================================
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
# fmt: off
|
| 145 |
+
# psutil.virtual_memory()
|
| 146 |
+
svmem = namedtuple(
|
| 147 |
+
'svmem', ['total', 'available', 'percent', 'used', 'free',
|
| 148 |
+
'active', 'inactive', 'buffers', 'cached', 'shared', 'wired'])
|
| 149 |
+
# psutil.cpu_times()
|
| 150 |
+
scputimes = namedtuple(
|
| 151 |
+
'scputimes', ['user', 'nice', 'system', 'idle', 'irq'])
|
| 152 |
+
# psutil.Process.memory_info()
|
| 153 |
+
pmem = namedtuple('pmem', ['rss', 'vms', 'text', 'data', 'stack'])
|
| 154 |
+
# psutil.Process.memory_full_info()
|
| 155 |
+
pfullmem = pmem
|
| 156 |
+
# psutil.Process.cpu_times()
|
| 157 |
+
pcputimes = namedtuple('pcputimes',
|
| 158 |
+
['user', 'system', 'children_user', 'children_system'])
|
| 159 |
+
# psutil.Process.memory_maps(grouped=True)
|
| 160 |
+
pmmap_grouped = namedtuple(
|
| 161 |
+
'pmmap_grouped', 'path rss, private, ref_count, shadow_count')
|
| 162 |
+
# psutil.Process.memory_maps(grouped=False)
|
| 163 |
+
pmmap_ext = namedtuple(
|
| 164 |
+
'pmmap_ext', 'addr, perms path rss, private, ref_count, shadow_count')
|
| 165 |
+
# psutil.disk_io_counters()
|
| 166 |
+
if FREEBSD:
|
| 167 |
+
sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
|
| 168 |
+
'read_bytes', 'write_bytes',
|
| 169 |
+
'read_time', 'write_time',
|
| 170 |
+
'busy_time'])
|
| 171 |
+
else:
|
| 172 |
+
sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
|
| 173 |
+
'read_bytes', 'write_bytes'])
|
| 174 |
+
# fmt: on
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
# =====================================================================
|
| 178 |
+
# --- memory
|
| 179 |
+
# =====================================================================
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def virtual_memory():
|
| 183 |
+
mem = cext.virtual_mem()
|
| 184 |
+
if NETBSD:
|
| 185 |
+
total, free, active, inactive, wired, cached = mem
|
| 186 |
+
# On NetBSD buffers and shared mem is determined via /proc.
|
| 187 |
+
# The C ext set them to 0.
|
| 188 |
+
with open('/proc/meminfo', 'rb') as f:
|
| 189 |
+
for line in f:
|
| 190 |
+
if line.startswith(b'Buffers:'):
|
| 191 |
+
buffers = int(line.split()[1]) * 1024
|
| 192 |
+
elif line.startswith(b'MemShared:'):
|
| 193 |
+
shared = int(line.split()[1]) * 1024
|
| 194 |
+
# Before avail was calculated as (inactive + cached + free),
|
| 195 |
+
# same as zabbix, but it turned out it could exceed total (see
|
| 196 |
+
# #2233), so zabbix seems to be wrong. Htop calculates it
|
| 197 |
+
# differently, and the used value seem more realistic, so let's
|
| 198 |
+
# match htop.
|
| 199 |
+
# https://github.com/htop-dev/htop/blob/e7f447b/netbsd/NetBSDProcessList.c#L162 # noqa
|
| 200 |
+
# https://github.com/zabbix/zabbix/blob/af5e0f8/src/libs/zbxsysinfo/netbsd/memory.c#L135 # noqa
|
| 201 |
+
used = active + wired
|
| 202 |
+
avail = total - used
|
| 203 |
+
else:
|
| 204 |
+
total, free, active, inactive, wired, cached, buffers, shared = mem
|
| 205 |
+
# matches freebsd-memory CLI:
|
| 206 |
+
# * https://people.freebsd.org/~rse/dist/freebsd-memory
|
| 207 |
+
# * https://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
|
| 208 |
+
# matches zabbix:
|
| 209 |
+
# * https://github.com/zabbix/zabbix/blob/af5e0f8/src/libs/zbxsysinfo/freebsd/memory.c#L143 # noqa
|
| 210 |
+
avail = inactive + cached + free
|
| 211 |
+
used = active + wired + cached
|
| 212 |
+
|
| 213 |
+
percent = usage_percent((total - avail), total, round_=1)
|
| 214 |
+
return svmem(
|
| 215 |
+
total,
|
| 216 |
+
avail,
|
| 217 |
+
percent,
|
| 218 |
+
used,
|
| 219 |
+
free,
|
| 220 |
+
active,
|
| 221 |
+
inactive,
|
| 222 |
+
buffers,
|
| 223 |
+
cached,
|
| 224 |
+
shared,
|
| 225 |
+
wired,
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def swap_memory():
|
| 230 |
+
"""System swap memory as (total, used, free, sin, sout) namedtuple."""
|
| 231 |
+
total, used, free, sin, sout = cext.swap_mem()
|
| 232 |
+
percent = usage_percent(used, total, round_=1)
|
| 233 |
+
return _common.sswap(total, used, free, percent, sin, sout)
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
# =====================================================================
|
| 237 |
+
# --- CPU
|
| 238 |
+
# =====================================================================
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def cpu_times():
|
| 242 |
+
"""Return system per-CPU times as a namedtuple."""
|
| 243 |
+
user, nice, system, idle, irq = cext.cpu_times()
|
| 244 |
+
return scputimes(user, nice, system, idle, irq)
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
if HAS_PER_CPU_TIMES:
|
| 248 |
+
|
| 249 |
+
def per_cpu_times():
|
| 250 |
+
"""Return system CPU times as a namedtuple."""
|
| 251 |
+
ret = []
|
| 252 |
+
for cpu_t in cext.per_cpu_times():
|
| 253 |
+
user, nice, system, idle, irq = cpu_t
|
| 254 |
+
item = scputimes(user, nice, system, idle, irq)
|
| 255 |
+
ret.append(item)
|
| 256 |
+
return ret
|
| 257 |
+
|
| 258 |
+
else:
|
| 259 |
+
# XXX
|
| 260 |
+
# Ok, this is very dirty.
|
| 261 |
+
# On FreeBSD < 8 we cannot gather per-cpu information, see:
|
| 262 |
+
# https://github.com/giampaolo/psutil/issues/226
|
| 263 |
+
# If num cpus > 1, on first call we return single cpu times to avoid a
|
| 264 |
+
# crash at psutil import time.
|
| 265 |
+
# Next calls will fail with NotImplementedError
|
| 266 |
+
def per_cpu_times():
|
| 267 |
+
"""Return system CPU times as a namedtuple."""
|
| 268 |
+
if cpu_count_logical() == 1:
|
| 269 |
+
return [cpu_times()]
|
| 270 |
+
if per_cpu_times.__called__:
|
| 271 |
+
msg = "supported only starting from FreeBSD 8"
|
| 272 |
+
raise NotImplementedError(msg)
|
| 273 |
+
per_cpu_times.__called__ = True
|
| 274 |
+
return [cpu_times()]
|
| 275 |
+
|
| 276 |
+
per_cpu_times.__called__ = False
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
def cpu_count_logical():
|
| 280 |
+
"""Return the number of logical CPUs in the system."""
|
| 281 |
+
return cext.cpu_count_logical()
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
if OPENBSD or NETBSD:
|
| 285 |
+
|
| 286 |
+
def cpu_count_cores():
|
| 287 |
+
# OpenBSD and NetBSD do not implement this.
|
| 288 |
+
return 1 if cpu_count_logical() == 1 else None
|
| 289 |
+
|
| 290 |
+
else:
|
| 291 |
+
|
| 292 |
+
def cpu_count_cores():
|
| 293 |
+
"""Return the number of CPU cores in the system."""
|
| 294 |
+
# From the C module we'll get an XML string similar to this:
|
| 295 |
+
# http://manpages.ubuntu.com/manpages/precise/man4/smp.4freebsd.html
|
| 296 |
+
# We may get None in case "sysctl kern.sched.topology_spec"
|
| 297 |
+
# is not supported on this BSD version, in which case we'll mimic
|
| 298 |
+
# os.cpu_count() and return None.
|
| 299 |
+
ret = None
|
| 300 |
+
s = cext.cpu_topology()
|
| 301 |
+
if s is not None:
|
| 302 |
+
# get rid of padding chars appended at the end of the string
|
| 303 |
+
index = s.rfind("</groups>")
|
| 304 |
+
if index != -1:
|
| 305 |
+
s = s[: index + 9]
|
| 306 |
+
root = ElementTree.fromstring(s)
|
| 307 |
+
try:
|
| 308 |
+
ret = len(root.findall('group/children/group/cpu')) or None
|
| 309 |
+
finally:
|
| 310 |
+
# needed otherwise it will memleak
|
| 311 |
+
root.clear()
|
| 312 |
+
if not ret:
|
| 313 |
+
# If logical CPUs == 1 it's obvious we' have only 1 core.
|
| 314 |
+
if cpu_count_logical() == 1:
|
| 315 |
+
return 1
|
| 316 |
+
return ret
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def cpu_stats():
|
| 320 |
+
"""Return various CPU stats as a named tuple."""
|
| 321 |
+
if FREEBSD:
|
| 322 |
+
# Note: the C ext is returning some metrics we are not exposing:
|
| 323 |
+
# traps.
|
| 324 |
+
ctxsw, intrs, soft_intrs, syscalls, _traps = cext.cpu_stats()
|
| 325 |
+
elif NETBSD:
|
| 326 |
+
# XXX
|
| 327 |
+
# Note about intrs: the C extension returns 0. intrs
|
| 328 |
+
# can be determined via /proc/stat; it has the same value as
|
| 329 |
+
# soft_intrs thought so the kernel is faking it (?).
|
| 330 |
+
#
|
| 331 |
+
# Note about syscalls: the C extension always sets it to 0 (?).
|
| 332 |
+
#
|
| 333 |
+
# Note: the C ext is returning some metrics we are not exposing:
|
| 334 |
+
# traps, faults and forks.
|
| 335 |
+
ctxsw, intrs, soft_intrs, syscalls, _traps, _faults, _forks = (
|
| 336 |
+
cext.cpu_stats()
|
| 337 |
+
)
|
| 338 |
+
with open('/proc/stat', 'rb') as f:
|
| 339 |
+
for line in f:
|
| 340 |
+
if line.startswith(b'intr'):
|
| 341 |
+
intrs = int(line.split()[1])
|
| 342 |
+
elif OPENBSD:
|
| 343 |
+
# Note: the C ext is returning some metrics we are not exposing:
|
| 344 |
+
# traps, faults and forks.
|
| 345 |
+
ctxsw, intrs, soft_intrs, syscalls, _traps, _faults, _forks = (
|
| 346 |
+
cext.cpu_stats()
|
| 347 |
+
)
|
| 348 |
+
return _common.scpustats(ctxsw, intrs, soft_intrs, syscalls)
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
if FREEBSD:
|
| 352 |
+
|
| 353 |
+
def cpu_freq():
|
| 354 |
+
"""Return frequency metrics for CPUs. As of Dec 2018 only
|
| 355 |
+
CPU 0 appears to be supported by FreeBSD and all other cores
|
| 356 |
+
match the frequency of CPU 0.
|
| 357 |
+
"""
|
| 358 |
+
ret = []
|
| 359 |
+
num_cpus = cpu_count_logical()
|
| 360 |
+
for cpu in range(num_cpus):
|
| 361 |
+
try:
|
| 362 |
+
current, available_freq = cext.cpu_freq(cpu)
|
| 363 |
+
except NotImplementedError:
|
| 364 |
+
continue
|
| 365 |
+
if available_freq:
|
| 366 |
+
try:
|
| 367 |
+
min_freq = int(available_freq.split(" ")[-1].split("/")[0])
|
| 368 |
+
except (IndexError, ValueError):
|
| 369 |
+
min_freq = None
|
| 370 |
+
try:
|
| 371 |
+
max_freq = int(available_freq.split(" ")[0].split("/")[0])
|
| 372 |
+
except (IndexError, ValueError):
|
| 373 |
+
max_freq = None
|
| 374 |
+
ret.append(_common.scpufreq(current, min_freq, max_freq))
|
| 375 |
+
return ret
|
| 376 |
+
|
| 377 |
+
elif OPENBSD:
|
| 378 |
+
|
| 379 |
+
def cpu_freq():
|
| 380 |
+
curr = float(cext.cpu_freq())
|
| 381 |
+
return [_common.scpufreq(curr, 0.0, 0.0)]
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
# =====================================================================
|
| 385 |
+
# --- disks
|
| 386 |
+
# =====================================================================
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
def disk_partitions(all=False):
|
| 390 |
+
"""Return mounted disk partitions as a list of namedtuples.
|
| 391 |
+
'all' argument is ignored, see:
|
| 392 |
+
https://github.com/giampaolo/psutil/issues/906.
|
| 393 |
+
"""
|
| 394 |
+
retlist = []
|
| 395 |
+
partitions = cext.disk_partitions()
|
| 396 |
+
for partition in partitions:
|
| 397 |
+
device, mountpoint, fstype, opts = partition
|
| 398 |
+
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
|
| 399 |
+
retlist.append(ntuple)
|
| 400 |
+
return retlist
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
disk_usage = _psposix.disk_usage
|
| 404 |
+
disk_io_counters = cext.disk_io_counters
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
# =====================================================================
|
| 408 |
+
# --- network
|
| 409 |
+
# =====================================================================
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
net_io_counters = cext.net_io_counters
|
| 413 |
+
net_if_addrs = cext_posix.net_if_addrs
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
def net_if_stats():
|
| 417 |
+
"""Get NIC stats (isup, duplex, speed, mtu)."""
|
| 418 |
+
names = net_io_counters().keys()
|
| 419 |
+
ret = {}
|
| 420 |
+
for name in names:
|
| 421 |
+
try:
|
| 422 |
+
mtu = cext_posix.net_if_mtu(name)
|
| 423 |
+
flags = cext_posix.net_if_flags(name)
|
| 424 |
+
duplex, speed = cext_posix.net_if_duplex_speed(name)
|
| 425 |
+
except OSError as err:
|
| 426 |
+
# https://github.com/giampaolo/psutil/issues/1279
|
| 427 |
+
if err.errno != errno.ENODEV:
|
| 428 |
+
raise
|
| 429 |
+
else:
|
| 430 |
+
if hasattr(_common, 'NicDuplex'):
|
| 431 |
+
duplex = _common.NicDuplex(duplex)
|
| 432 |
+
output_flags = ','.join(flags)
|
| 433 |
+
isup = 'running' in flags
|
| 434 |
+
ret[name] = _common.snicstats(
|
| 435 |
+
isup, duplex, speed, mtu, output_flags
|
| 436 |
+
)
|
| 437 |
+
return ret
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
def net_connections(kind):
|
| 441 |
+
"""System-wide network connections."""
|
| 442 |
+
if kind not in _common.conn_tmap:
|
| 443 |
+
raise ValueError(
|
| 444 |
+
"invalid %r kind argument; choose between %s"
|
| 445 |
+
% (kind, ', '.join([repr(x) for x in conn_tmap]))
|
| 446 |
+
)
|
| 447 |
+
families, types = conn_tmap[kind]
|
| 448 |
+
ret = set()
|
| 449 |
+
|
| 450 |
+
if OPENBSD:
|
| 451 |
+
rawlist = cext.net_connections(-1, families, types)
|
| 452 |
+
elif NETBSD:
|
| 453 |
+
rawlist = cext.net_connections(-1, kind)
|
| 454 |
+
else: # FreeBSD
|
| 455 |
+
rawlist = cext.net_connections(families, types)
|
| 456 |
+
|
| 457 |
+
for item in rawlist:
|
| 458 |
+
fd, fam, type, laddr, raddr, status, pid = item
|
| 459 |
+
nt = conn_to_ntuple(
|
| 460 |
+
fd, fam, type, laddr, raddr, status, TCP_STATUSES, pid
|
| 461 |
+
)
|
| 462 |
+
ret.add(nt)
|
| 463 |
+
return list(ret)
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
# =====================================================================
|
| 467 |
+
# --- sensors
|
| 468 |
+
# =====================================================================
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
if FREEBSD:
|
| 472 |
+
|
| 473 |
+
def sensors_battery():
|
| 474 |
+
"""Return battery info."""
|
| 475 |
+
try:
|
| 476 |
+
percent, minsleft, power_plugged = cext.sensors_battery()
|
| 477 |
+
except NotImplementedError:
|
| 478 |
+
# See: https://github.com/giampaolo/psutil/issues/1074
|
| 479 |
+
return None
|
| 480 |
+
power_plugged = power_plugged == 1
|
| 481 |
+
if power_plugged:
|
| 482 |
+
secsleft = _common.POWER_TIME_UNLIMITED
|
| 483 |
+
elif minsleft == -1:
|
| 484 |
+
secsleft = _common.POWER_TIME_UNKNOWN
|
| 485 |
+
else:
|
| 486 |
+
secsleft = minsleft * 60
|
| 487 |
+
return _common.sbattery(percent, secsleft, power_plugged)
|
| 488 |
+
|
| 489 |
+
def sensors_temperatures():
|
| 490 |
+
"""Return CPU cores temperatures if available, else an empty dict."""
|
| 491 |
+
ret = defaultdict(list)
|
| 492 |
+
num_cpus = cpu_count_logical()
|
| 493 |
+
for cpu in range(num_cpus):
|
| 494 |
+
try:
|
| 495 |
+
current, high = cext.sensors_cpu_temperature(cpu)
|
| 496 |
+
if high <= 0:
|
| 497 |
+
high = None
|
| 498 |
+
name = "Core %s" % cpu
|
| 499 |
+
ret["coretemp"].append(
|
| 500 |
+
_common.shwtemp(name, current, high, high)
|
| 501 |
+
)
|
| 502 |
+
except NotImplementedError:
|
| 503 |
+
pass
|
| 504 |
+
|
| 505 |
+
return ret
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
# =====================================================================
|
| 509 |
+
# --- other system functions
|
| 510 |
+
# =====================================================================
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def boot_time():
|
| 514 |
+
"""The system boot time expressed in seconds since the epoch."""
|
| 515 |
+
return cext.boot_time()
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
def users():
|
| 519 |
+
"""Return currently connected users as a list of namedtuples."""
|
| 520 |
+
retlist = []
|
| 521 |
+
rawlist = cext.users()
|
| 522 |
+
for item in rawlist:
|
| 523 |
+
user, tty, hostname, tstamp, pid = item
|
| 524 |
+
if pid == -1:
|
| 525 |
+
assert OPENBSD
|
| 526 |
+
pid = None
|
| 527 |
+
if tty == '~':
|
| 528 |
+
continue # reboot or shutdown
|
| 529 |
+
nt = _common.suser(user, tty or None, hostname, tstamp, pid)
|
| 530 |
+
retlist.append(nt)
|
| 531 |
+
return retlist
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
# =====================================================================
|
| 535 |
+
# --- processes
|
| 536 |
+
# =====================================================================
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
@memoize
|
| 540 |
+
def _pid_0_exists():
|
| 541 |
+
try:
|
| 542 |
+
Process(0).name()
|
| 543 |
+
except NoSuchProcess:
|
| 544 |
+
return False
|
| 545 |
+
except AccessDenied:
|
| 546 |
+
return True
|
| 547 |
+
else:
|
| 548 |
+
return True
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
def pids():
|
| 552 |
+
"""Returns a list of PIDs currently running on the system."""
|
| 553 |
+
ret = cext.pids()
|
| 554 |
+
if OPENBSD and (0 not in ret) and _pid_0_exists():
|
| 555 |
+
# On OpenBSD the kernel does not return PID 0 (neither does
|
| 556 |
+
# ps) but it's actually querable (Process(0) will succeed).
|
| 557 |
+
ret.insert(0, 0)
|
| 558 |
+
return ret
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
if NETBSD:
|
| 562 |
+
|
| 563 |
+
def pid_exists(pid):
|
| 564 |
+
exists = _psposix.pid_exists(pid)
|
| 565 |
+
if not exists:
|
| 566 |
+
# We do this because _psposix.pid_exists() lies in case of
|
| 567 |
+
# zombie processes.
|
| 568 |
+
return pid in pids()
|
| 569 |
+
else:
|
| 570 |
+
return True
|
| 571 |
+
|
| 572 |
+
elif OPENBSD:
|
| 573 |
+
|
| 574 |
+
def pid_exists(pid):
|
| 575 |
+
exists = _psposix.pid_exists(pid)
|
| 576 |
+
if not exists:
|
| 577 |
+
return False
|
| 578 |
+
else:
|
| 579 |
+
# OpenBSD seems to be the only BSD platform where
|
| 580 |
+
# _psposix.pid_exists() returns True for thread IDs (tids),
|
| 581 |
+
# so we can't use it.
|
| 582 |
+
return pid in pids()
|
| 583 |
+
|
| 584 |
+
else: # FreeBSD
|
| 585 |
+
pid_exists = _psposix.pid_exists
|
| 586 |
+
|
| 587 |
+
|
| 588 |
+
def is_zombie(pid):
|
| 589 |
+
try:
|
| 590 |
+
st = cext.proc_oneshot_info(pid)[kinfo_proc_map['status']]
|
| 591 |
+
return PROC_STATUSES.get(st) == _common.STATUS_ZOMBIE
|
| 592 |
+
except OSError:
|
| 593 |
+
return False
|
| 594 |
+
|
| 595 |
+
|
| 596 |
+
def wrap_exceptions(fun):
|
| 597 |
+
"""Decorator which translates bare OSError exceptions into
|
| 598 |
+
NoSuchProcess and AccessDenied.
|
| 599 |
+
"""
|
| 600 |
+
|
| 601 |
+
@functools.wraps(fun)
|
| 602 |
+
def wrapper(self, *args, **kwargs):
|
| 603 |
+
try:
|
| 604 |
+
return fun(self, *args, **kwargs)
|
| 605 |
+
except ProcessLookupError:
|
| 606 |
+
if is_zombie(self.pid):
|
| 607 |
+
raise ZombieProcess(self.pid, self._name, self._ppid)
|
| 608 |
+
else:
|
| 609 |
+
raise NoSuchProcess(self.pid, self._name)
|
| 610 |
+
except PermissionError:
|
| 611 |
+
raise AccessDenied(self.pid, self._name)
|
| 612 |
+
except OSError:
|
| 613 |
+
if self.pid == 0:
|
| 614 |
+
if 0 in pids():
|
| 615 |
+
raise AccessDenied(self.pid, self._name)
|
| 616 |
+
else:
|
| 617 |
+
raise
|
| 618 |
+
raise
|
| 619 |
+
|
| 620 |
+
return wrapper
|
| 621 |
+
|
| 622 |
+
|
| 623 |
+
@contextlib.contextmanager
|
| 624 |
+
def wrap_exceptions_procfs(inst):
|
| 625 |
+
"""Same as above, for routines relying on reading /proc fs."""
|
| 626 |
+
try:
|
| 627 |
+
yield
|
| 628 |
+
except (ProcessLookupError, FileNotFoundError):
|
| 629 |
+
# ENOENT (no such file or directory) gets raised on open().
|
| 630 |
+
# ESRCH (no such process) can get raised on read() if
|
| 631 |
+
# process is gone in meantime.
|
| 632 |
+
if is_zombie(inst.pid):
|
| 633 |
+
raise ZombieProcess(inst.pid, inst._name, inst._ppid)
|
| 634 |
+
else:
|
| 635 |
+
raise NoSuchProcess(inst.pid, inst._name)
|
| 636 |
+
except PermissionError:
|
| 637 |
+
raise AccessDenied(inst.pid, inst._name)
|
| 638 |
+
|
| 639 |
+
|
| 640 |
+
class Process:
|
| 641 |
+
"""Wrapper class around underlying C implementation."""
|
| 642 |
+
|
| 643 |
+
__slots__ = ["_cache", "_name", "_ppid", "pid"]
|
| 644 |
+
|
| 645 |
+
def __init__(self, pid):
|
| 646 |
+
self.pid = pid
|
| 647 |
+
self._name = None
|
| 648 |
+
self._ppid = None
|
| 649 |
+
|
| 650 |
+
def _assert_alive(self):
|
| 651 |
+
"""Raise NSP if the process disappeared on us."""
|
| 652 |
+
# For those C function who do not raise NSP, possibly returning
|
| 653 |
+
# incorrect or incomplete result.
|
| 654 |
+
cext.proc_name(self.pid)
|
| 655 |
+
|
| 656 |
+
@wrap_exceptions
|
| 657 |
+
@memoize_when_activated
|
| 658 |
+
def oneshot(self):
|
| 659 |
+
"""Retrieves multiple process info in one shot as a raw tuple."""
|
| 660 |
+
ret = cext.proc_oneshot_info(self.pid)
|
| 661 |
+
assert len(ret) == len(kinfo_proc_map)
|
| 662 |
+
return ret
|
| 663 |
+
|
| 664 |
+
def oneshot_enter(self):
|
| 665 |
+
self.oneshot.cache_activate(self)
|
| 666 |
+
|
| 667 |
+
def oneshot_exit(self):
|
| 668 |
+
self.oneshot.cache_deactivate(self)
|
| 669 |
+
|
| 670 |
+
@wrap_exceptions
|
| 671 |
+
def name(self):
|
| 672 |
+
name = self.oneshot()[kinfo_proc_map['name']]
|
| 673 |
+
return name if name is not None else cext.proc_name(self.pid)
|
| 674 |
+
|
| 675 |
+
@wrap_exceptions
|
| 676 |
+
def exe(self):
|
| 677 |
+
if FREEBSD:
|
| 678 |
+
if self.pid == 0:
|
| 679 |
+
return '' # else NSP
|
| 680 |
+
return cext.proc_exe(self.pid)
|
| 681 |
+
elif NETBSD:
|
| 682 |
+
if self.pid == 0:
|
| 683 |
+
# /proc/0 dir exists but /proc/0/exe doesn't
|
| 684 |
+
return ""
|
| 685 |
+
with wrap_exceptions_procfs(self):
|
| 686 |
+
return os.readlink("/proc/%s/exe" % self.pid)
|
| 687 |
+
else:
|
| 688 |
+
# OpenBSD: exe cannot be determined; references:
|
| 689 |
+
# https://chromium.googlesource.com/chromium/src/base/+/
|
| 690 |
+
# master/base_paths_posix.cc
|
| 691 |
+
# We try our best guess by using which against the first
|
| 692 |
+
# cmdline arg (may return None).
|
| 693 |
+
cmdline = self.cmdline()
|
| 694 |
+
if cmdline:
|
| 695 |
+
return which(cmdline[0]) or ""
|
| 696 |
+
else:
|
| 697 |
+
return ""
|
| 698 |
+
|
| 699 |
+
@wrap_exceptions
|
| 700 |
+
def cmdline(self):
|
| 701 |
+
if OPENBSD and self.pid == 0:
|
| 702 |
+
return [] # ...else it crashes
|
| 703 |
+
elif NETBSD:
|
| 704 |
+
# XXX - most of the times the underlying sysctl() call on
|
| 705 |
+
# NetBSD and OpenBSD returns a truncated string. Also
|
| 706 |
+
# /proc/pid/cmdline behaves the same so it looks like this
|
| 707 |
+
# is a kernel bug.
|
| 708 |
+
try:
|
| 709 |
+
return cext.proc_cmdline(self.pid)
|
| 710 |
+
except OSError as err:
|
| 711 |
+
if err.errno == errno.EINVAL:
|
| 712 |
+
if is_zombie(self.pid):
|
| 713 |
+
raise ZombieProcess(self.pid, self._name, self._ppid)
|
| 714 |
+
elif not pid_exists(self.pid):
|
| 715 |
+
raise NoSuchProcess(self.pid, self._name, self._ppid)
|
| 716 |
+
else:
|
| 717 |
+
# XXX: this happens with unicode tests. It means the C
|
| 718 |
+
# routine is unable to decode invalid unicode chars.
|
| 719 |
+
debug("ignoring %r and returning an empty list" % err)
|
| 720 |
+
return []
|
| 721 |
+
else:
|
| 722 |
+
raise
|
| 723 |
+
else:
|
| 724 |
+
return cext.proc_cmdline(self.pid)
|
| 725 |
+
|
| 726 |
+
@wrap_exceptions
|
| 727 |
+
def environ(self):
|
| 728 |
+
return cext.proc_environ(self.pid)
|
| 729 |
+
|
| 730 |
+
@wrap_exceptions
|
| 731 |
+
def terminal(self):
|
| 732 |
+
tty_nr = self.oneshot()[kinfo_proc_map['ttynr']]
|
| 733 |
+
tmap = _psposix.get_terminal_map()
|
| 734 |
+
try:
|
| 735 |
+
return tmap[tty_nr]
|
| 736 |
+
except KeyError:
|
| 737 |
+
return None
|
| 738 |
+
|
| 739 |
+
@wrap_exceptions
|
| 740 |
+
def ppid(self):
|
| 741 |
+
self._ppid = self.oneshot()[kinfo_proc_map['ppid']]
|
| 742 |
+
return self._ppid
|
| 743 |
+
|
| 744 |
+
@wrap_exceptions
|
| 745 |
+
def uids(self):
|
| 746 |
+
rawtuple = self.oneshot()
|
| 747 |
+
return _common.puids(
|
| 748 |
+
rawtuple[kinfo_proc_map['real_uid']],
|
| 749 |
+
rawtuple[kinfo_proc_map['effective_uid']],
|
| 750 |
+
rawtuple[kinfo_proc_map['saved_uid']],
|
| 751 |
+
)
|
| 752 |
+
|
| 753 |
+
@wrap_exceptions
|
| 754 |
+
def gids(self):
|
| 755 |
+
rawtuple = self.oneshot()
|
| 756 |
+
return _common.pgids(
|
| 757 |
+
rawtuple[kinfo_proc_map['real_gid']],
|
| 758 |
+
rawtuple[kinfo_proc_map['effective_gid']],
|
| 759 |
+
rawtuple[kinfo_proc_map['saved_gid']],
|
| 760 |
+
)
|
| 761 |
+
|
| 762 |
+
@wrap_exceptions
|
| 763 |
+
def cpu_times(self):
|
| 764 |
+
rawtuple = self.oneshot()
|
| 765 |
+
return _common.pcputimes(
|
| 766 |
+
rawtuple[kinfo_proc_map['user_time']],
|
| 767 |
+
rawtuple[kinfo_proc_map['sys_time']],
|
| 768 |
+
rawtuple[kinfo_proc_map['ch_user_time']],
|
| 769 |
+
rawtuple[kinfo_proc_map['ch_sys_time']],
|
| 770 |
+
)
|
| 771 |
+
|
| 772 |
+
if FREEBSD:
|
| 773 |
+
|
| 774 |
+
@wrap_exceptions
|
| 775 |
+
def cpu_num(self):
|
| 776 |
+
return self.oneshot()[kinfo_proc_map['cpunum']]
|
| 777 |
+
|
| 778 |
+
@wrap_exceptions
|
| 779 |
+
def memory_info(self):
|
| 780 |
+
rawtuple = self.oneshot()
|
| 781 |
+
return pmem(
|
| 782 |
+
rawtuple[kinfo_proc_map['rss']],
|
| 783 |
+
rawtuple[kinfo_proc_map['vms']],
|
| 784 |
+
rawtuple[kinfo_proc_map['memtext']],
|
| 785 |
+
rawtuple[kinfo_proc_map['memdata']],
|
| 786 |
+
rawtuple[kinfo_proc_map['memstack']],
|
| 787 |
+
)
|
| 788 |
+
|
| 789 |
+
memory_full_info = memory_info
|
| 790 |
+
|
| 791 |
+
@wrap_exceptions
|
| 792 |
+
def create_time(self):
|
| 793 |
+
return self.oneshot()[kinfo_proc_map['create_time']]
|
| 794 |
+
|
| 795 |
+
@wrap_exceptions
|
| 796 |
+
def num_threads(self):
|
| 797 |
+
if HAS_PROC_NUM_THREADS:
|
| 798 |
+
# FreeBSD
|
| 799 |
+
return cext.proc_num_threads(self.pid)
|
| 800 |
+
else:
|
| 801 |
+
return len(self.threads())
|
| 802 |
+
|
| 803 |
+
@wrap_exceptions
|
| 804 |
+
def num_ctx_switches(self):
|
| 805 |
+
rawtuple = self.oneshot()
|
| 806 |
+
return _common.pctxsw(
|
| 807 |
+
rawtuple[kinfo_proc_map['ctx_switches_vol']],
|
| 808 |
+
rawtuple[kinfo_proc_map['ctx_switches_unvol']],
|
| 809 |
+
)
|
| 810 |
+
|
| 811 |
+
@wrap_exceptions
|
| 812 |
+
def threads(self):
|
| 813 |
+
# Note: on OpenSBD this (/dev/mem) requires root access.
|
| 814 |
+
rawlist = cext.proc_threads(self.pid)
|
| 815 |
+
retlist = []
|
| 816 |
+
for thread_id, utime, stime in rawlist:
|
| 817 |
+
ntuple = _common.pthread(thread_id, utime, stime)
|
| 818 |
+
retlist.append(ntuple)
|
| 819 |
+
if OPENBSD:
|
| 820 |
+
self._assert_alive()
|
| 821 |
+
return retlist
|
| 822 |
+
|
| 823 |
+
@wrap_exceptions
|
| 824 |
+
def net_connections(self, kind='inet'):
|
| 825 |
+
if kind not in conn_tmap:
|
| 826 |
+
raise ValueError(
|
| 827 |
+
"invalid %r kind argument; choose between %s"
|
| 828 |
+
% (kind, ', '.join([repr(x) for x in conn_tmap]))
|
| 829 |
+
)
|
| 830 |
+
families, types = conn_tmap[kind]
|
| 831 |
+
ret = []
|
| 832 |
+
|
| 833 |
+
if NETBSD:
|
| 834 |
+
rawlist = cext.net_connections(self.pid, kind)
|
| 835 |
+
elif OPENBSD:
|
| 836 |
+
rawlist = cext.net_connections(self.pid, families, types)
|
| 837 |
+
else:
|
| 838 |
+
rawlist = cext.proc_net_connections(self.pid, families, types)
|
| 839 |
+
|
| 840 |
+
for item in rawlist:
|
| 841 |
+
fd, fam, type, laddr, raddr, status = item[:6]
|
| 842 |
+
if FREEBSD:
|
| 843 |
+
if (fam not in families) or (type not in types):
|
| 844 |
+
continue
|
| 845 |
+
nt = conn_to_ntuple(
|
| 846 |
+
fd, fam, type, laddr, raddr, status, TCP_STATUSES
|
| 847 |
+
)
|
| 848 |
+
ret.append(nt)
|
| 849 |
+
|
| 850 |
+
self._assert_alive()
|
| 851 |
+
return ret
|
| 852 |
+
|
| 853 |
+
@wrap_exceptions
|
| 854 |
+
def wait(self, timeout=None):
|
| 855 |
+
return _psposix.wait_pid(self.pid, timeout, self._name)
|
| 856 |
+
|
| 857 |
+
@wrap_exceptions
|
| 858 |
+
def nice_get(self):
|
| 859 |
+
return cext_posix.getpriority(self.pid)
|
| 860 |
+
|
| 861 |
+
@wrap_exceptions
|
| 862 |
+
def nice_set(self, value):
|
| 863 |
+
return cext_posix.setpriority(self.pid, value)
|
| 864 |
+
|
| 865 |
+
@wrap_exceptions
|
| 866 |
+
def status(self):
|
| 867 |
+
code = self.oneshot()[kinfo_proc_map['status']]
|
| 868 |
+
# XXX is '?' legit? (we're not supposed to return it anyway)
|
| 869 |
+
return PROC_STATUSES.get(code, '?')
|
| 870 |
+
|
| 871 |
+
@wrap_exceptions
|
| 872 |
+
def io_counters(self):
|
| 873 |
+
rawtuple = self.oneshot()
|
| 874 |
+
return _common.pio(
|
| 875 |
+
rawtuple[kinfo_proc_map['read_io_count']],
|
| 876 |
+
rawtuple[kinfo_proc_map['write_io_count']],
|
| 877 |
+
-1,
|
| 878 |
+
-1,
|
| 879 |
+
)
|
| 880 |
+
|
| 881 |
+
@wrap_exceptions
|
| 882 |
+
def cwd(self):
|
| 883 |
+
"""Return process current working directory."""
|
| 884 |
+
# sometimes we get an empty string, in which case we turn
|
| 885 |
+
# it into None
|
| 886 |
+
if OPENBSD and self.pid == 0:
|
| 887 |
+
return "" # ...else it would raise EINVAL
|
| 888 |
+
elif NETBSD or HAS_PROC_OPEN_FILES:
|
| 889 |
+
# FreeBSD < 8 does not support functions based on
|
| 890 |
+
# kinfo_getfile() and kinfo_getvmmap()
|
| 891 |
+
return cext.proc_cwd(self.pid)
|
| 892 |
+
else:
|
| 893 |
+
raise NotImplementedError(
|
| 894 |
+
"supported only starting from FreeBSD 8" if FREEBSD else ""
|
| 895 |
+
)
|
| 896 |
+
|
| 897 |
+
nt_mmap_grouped = namedtuple(
|
| 898 |
+
'mmap', 'path rss, private, ref_count, shadow_count'
|
| 899 |
+
)
|
| 900 |
+
nt_mmap_ext = namedtuple(
|
| 901 |
+
'mmap', 'addr, perms path rss, private, ref_count, shadow_count'
|
| 902 |
+
)
|
| 903 |
+
|
| 904 |
+
def _not_implemented(self):
|
| 905 |
+
raise NotImplementedError
|
| 906 |
+
|
| 907 |
+
# FreeBSD < 8 does not support functions based on kinfo_getfile()
|
| 908 |
+
# and kinfo_getvmmap()
|
| 909 |
+
if HAS_PROC_OPEN_FILES:
|
| 910 |
+
|
| 911 |
+
@wrap_exceptions
|
| 912 |
+
def open_files(self):
|
| 913 |
+
"""Return files opened by process as a list of namedtuples."""
|
| 914 |
+
rawlist = cext.proc_open_files(self.pid)
|
| 915 |
+
return [_common.popenfile(path, fd) for path, fd in rawlist]
|
| 916 |
+
|
| 917 |
+
else:
|
| 918 |
+
open_files = _not_implemented
|
| 919 |
+
|
| 920 |
+
# FreeBSD < 8 does not support functions based on kinfo_getfile()
|
| 921 |
+
# and kinfo_getvmmap()
|
| 922 |
+
if HAS_PROC_NUM_FDS:
|
| 923 |
+
|
| 924 |
+
@wrap_exceptions
|
| 925 |
+
def num_fds(self):
|
| 926 |
+
"""Return the number of file descriptors opened by this process."""
|
| 927 |
+
ret = cext.proc_num_fds(self.pid)
|
| 928 |
+
if NETBSD:
|
| 929 |
+
self._assert_alive()
|
| 930 |
+
return ret
|
| 931 |
+
|
| 932 |
+
else:
|
| 933 |
+
num_fds = _not_implemented
|
| 934 |
+
|
| 935 |
+
# --- FreeBSD only APIs
|
| 936 |
+
|
| 937 |
+
if FREEBSD:
|
| 938 |
+
|
| 939 |
+
@wrap_exceptions
|
| 940 |
+
def cpu_affinity_get(self):
|
| 941 |
+
return cext.proc_cpu_affinity_get(self.pid)
|
| 942 |
+
|
| 943 |
+
@wrap_exceptions
|
| 944 |
+
def cpu_affinity_set(self, cpus):
|
| 945 |
+
# Pre-emptively check if CPUs are valid because the C
|
| 946 |
+
# function has a weird behavior in case of invalid CPUs,
|
| 947 |
+
# see: https://github.com/giampaolo/psutil/issues/586
|
| 948 |
+
allcpus = tuple(range(len(per_cpu_times())))
|
| 949 |
+
for cpu in cpus:
|
| 950 |
+
if cpu not in allcpus:
|
| 951 |
+
raise ValueError(
|
| 952 |
+
"invalid CPU #%i (choose between %s)" % (cpu, allcpus)
|
| 953 |
+
)
|
| 954 |
+
try:
|
| 955 |
+
cext.proc_cpu_affinity_set(self.pid, cpus)
|
| 956 |
+
except OSError as err:
|
| 957 |
+
# 'man cpuset_setaffinity' about EDEADLK:
|
| 958 |
+
# <<the call would leave a thread without a valid CPU to run
|
| 959 |
+
# on because the set does not overlap with the thread's
|
| 960 |
+
# anonymous mask>>
|
| 961 |
+
if err.errno in {errno.EINVAL, errno.EDEADLK}:
|
| 962 |
+
for cpu in cpus:
|
| 963 |
+
if cpu not in allcpus:
|
| 964 |
+
raise ValueError(
|
| 965 |
+
"invalid CPU #%i (choose between %s)"
|
| 966 |
+
% (cpu, allcpus)
|
| 967 |
+
)
|
| 968 |
+
raise
|
| 969 |
+
|
| 970 |
+
@wrap_exceptions
|
| 971 |
+
def memory_maps(self):
|
| 972 |
+
return cext.proc_memory_maps(self.pid)
|
| 973 |
+
|
| 974 |
+
@wrap_exceptions
|
| 975 |
+
def rlimit(self, resource, limits=None):
|
| 976 |
+
if limits is None:
|
| 977 |
+
return cext.proc_getrlimit(self.pid, resource)
|
| 978 |
+
else:
|
| 979 |
+
if len(limits) != 2:
|
| 980 |
+
raise ValueError(
|
| 981 |
+
"second argument must be a (soft, hard) tuple, got %s"
|
| 982 |
+
% repr(limits)
|
| 983 |
+
)
|
| 984 |
+
soft, hard = limits
|
| 985 |
+
return cext.proc_setrlimit(self.pid, resource, soft, hard)
|
mplug_owl2/lib/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# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
|
| 2 |
+
# Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
# found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
"""Linux platform implementation."""
|
| 6 |
+
|
| 7 |
+
from __future__ import division
|
| 8 |
+
|
| 9 |
+
import base64
|
| 10 |
+
import collections
|
| 11 |
+
import errno
|
| 12 |
+
import functools
|
| 13 |
+
import glob
|
| 14 |
+
import os
|
| 15 |
+
import re
|
| 16 |
+
import socket
|
| 17 |
+
import struct
|
| 18 |
+
import sys
|
| 19 |
+
import warnings
|
| 20 |
+
from collections import defaultdict
|
| 21 |
+
from collections import namedtuple
|
| 22 |
+
|
| 23 |
+
from . import _common
|
| 24 |
+
from . import _psposix
|
| 25 |
+
from . import _psutil_linux as cext
|
| 26 |
+
from . import _psutil_posix as cext_posix
|
| 27 |
+
from ._common import NIC_DUPLEX_FULL
|
| 28 |
+
from ._common import NIC_DUPLEX_HALF
|
| 29 |
+
from ._common import NIC_DUPLEX_UNKNOWN
|
| 30 |
+
from ._common import AccessDenied
|
| 31 |
+
from ._common import NoSuchProcess
|
| 32 |
+
from ._common import ZombieProcess
|
| 33 |
+
from ._common import bcat
|
| 34 |
+
from ._common import cat
|
| 35 |
+
from ._common import debug
|
| 36 |
+
from ._common import decode
|
| 37 |
+
from ._common import get_procfs_path
|
| 38 |
+
from ._common import isfile_strict
|
| 39 |
+
from ._common import memoize
|
| 40 |
+
from ._common import memoize_when_activated
|
| 41 |
+
from ._common import open_binary
|
| 42 |
+
from ._common import open_text
|
| 43 |
+
from ._common import parse_environ_block
|
| 44 |
+
from ._common import path_exists_strict
|
| 45 |
+
from ._common import supports_ipv6
|
| 46 |
+
from ._common import usage_percent
|
| 47 |
+
from ._compat import PY3
|
| 48 |
+
from ._compat import FileNotFoundError
|
| 49 |
+
from ._compat import PermissionError
|
| 50 |
+
from ._compat import ProcessLookupError
|
| 51 |
+
from ._compat import b
|
| 52 |
+
from ._compat import basestring
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if PY3:
|
| 56 |
+
import enum
|
| 57 |
+
else:
|
| 58 |
+
enum = None
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# fmt: off
|
| 62 |
+
__extra__all__ = [
|
| 63 |
+
'PROCFS_PATH',
|
| 64 |
+
# io prio constants
|
| 65 |
+
"IOPRIO_CLASS_NONE", "IOPRIO_CLASS_RT", "IOPRIO_CLASS_BE",
|
| 66 |
+
"IOPRIO_CLASS_IDLE",
|
| 67 |
+
# connection status constants
|
| 68 |
+
"CONN_ESTABLISHED", "CONN_SYN_SENT", "CONN_SYN_RECV", "CONN_FIN_WAIT1",
|
| 69 |
+
"CONN_FIN_WAIT2", "CONN_TIME_WAIT", "CONN_CLOSE", "CONN_CLOSE_WAIT",
|
| 70 |
+
"CONN_LAST_ACK", "CONN_LISTEN", "CONN_CLOSING",
|
| 71 |
+
]
|
| 72 |
+
# fmt: on
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# =====================================================================
|
| 76 |
+
# --- globals
|
| 77 |
+
# =====================================================================
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
POWER_SUPPLY_PATH = "/sys/class/power_supply"
|
| 81 |
+
HAS_PROC_SMAPS = os.path.exists('/proc/%s/smaps' % os.getpid())
|
| 82 |
+
HAS_PROC_SMAPS_ROLLUP = os.path.exists('/proc/%s/smaps_rollup' % os.getpid())
|
| 83 |
+
HAS_PROC_IO_PRIORITY = hasattr(cext, "proc_ioprio_get")
|
| 84 |
+
HAS_CPU_AFFINITY = hasattr(cext, "proc_cpu_affinity_get")
|
| 85 |
+
|
| 86 |
+
# Number of clock ticks per second
|
| 87 |
+
CLOCK_TICKS = os.sysconf("SC_CLK_TCK")
|
| 88 |
+
PAGESIZE = cext_posix.getpagesize()
|
| 89 |
+
BOOT_TIME = None # set later
|
| 90 |
+
LITTLE_ENDIAN = sys.byteorder == 'little'
|
| 91 |
+
|
| 92 |
+
# "man iostat" states that sectors are equivalent with blocks and have
|
| 93 |
+
# a size of 512 bytes. Despite this value can be queried at runtime
|
| 94 |
+
# via /sys/block/{DISK}/queue/hw_sector_size and results may vary
|
| 95 |
+
# between 1k, 2k, or 4k... 512 appears to be a magic constant used
|
| 96 |
+
# throughout Linux source code:
|
| 97 |
+
# * https://stackoverflow.com/a/38136179/376587
|
| 98 |
+
# * https://lists.gt.net/linux/kernel/2241060
|
| 99 |
+
# * https://github.com/giampaolo/psutil/issues/1305
|
| 100 |
+
# * https://github.com/torvalds/linux/blob/
|
| 101 |
+
# 4f671fe2f9523a1ea206f63fe60a7c7b3a56d5c7/include/linux/bio.h#L99
|
| 102 |
+
# * https://lkml.org/lkml/2015/8/17/234
|
| 103 |
+
DISK_SECTOR_SIZE = 512
|
| 104 |
+
|
| 105 |
+
if enum is None:
|
| 106 |
+
AF_LINK = socket.AF_PACKET
|
| 107 |
+
else:
|
| 108 |
+
AddressFamily = enum.IntEnum(
|
| 109 |
+
'AddressFamily', {'AF_LINK': int(socket.AF_PACKET)}
|
| 110 |
+
)
|
| 111 |
+
AF_LINK = AddressFamily.AF_LINK
|
| 112 |
+
|
| 113 |
+
# ioprio_* constants http://linux.die.net/man/2/ioprio_get
|
| 114 |
+
if enum is None:
|
| 115 |
+
IOPRIO_CLASS_NONE = 0
|
| 116 |
+
IOPRIO_CLASS_RT = 1
|
| 117 |
+
IOPRIO_CLASS_BE = 2
|
| 118 |
+
IOPRIO_CLASS_IDLE = 3
|
| 119 |
+
else:
|
| 120 |
+
|
| 121 |
+
class IOPriority(enum.IntEnum):
|
| 122 |
+
IOPRIO_CLASS_NONE = 0
|
| 123 |
+
IOPRIO_CLASS_RT = 1
|
| 124 |
+
IOPRIO_CLASS_BE = 2
|
| 125 |
+
IOPRIO_CLASS_IDLE = 3
|
| 126 |
+
|
| 127 |
+
globals().update(IOPriority.__members__)
|
| 128 |
+
|
| 129 |
+
# See:
|
| 130 |
+
# https://github.com/torvalds/linux/blame/master/fs/proc/array.c
|
| 131 |
+
# ...and (TASK_* constants):
|
| 132 |
+
# https://github.com/torvalds/linux/blob/master/include/linux/sched.h
|
| 133 |
+
PROC_STATUSES = {
|
| 134 |
+
"R": _common.STATUS_RUNNING,
|
| 135 |
+
"S": _common.STATUS_SLEEPING,
|
| 136 |
+
"D": _common.STATUS_DISK_SLEEP,
|
| 137 |
+
"T": _common.STATUS_STOPPED,
|
| 138 |
+
"t": _common.STATUS_TRACING_STOP,
|
| 139 |
+
"Z": _common.STATUS_ZOMBIE,
|
| 140 |
+
"X": _common.STATUS_DEAD,
|
| 141 |
+
"x": _common.STATUS_DEAD,
|
| 142 |
+
"K": _common.STATUS_WAKE_KILL,
|
| 143 |
+
"W": _common.STATUS_WAKING,
|
| 144 |
+
"I": _common.STATUS_IDLE,
|
| 145 |
+
"P": _common.STATUS_PARKED,
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
# https://github.com/torvalds/linux/blob/master/include/net/tcp_states.h
|
| 149 |
+
TCP_STATUSES = {
|
| 150 |
+
"01": _common.CONN_ESTABLISHED,
|
| 151 |
+
"02": _common.CONN_SYN_SENT,
|
| 152 |
+
"03": _common.CONN_SYN_RECV,
|
| 153 |
+
"04": _common.CONN_FIN_WAIT1,
|
| 154 |
+
"05": _common.CONN_FIN_WAIT2,
|
| 155 |
+
"06": _common.CONN_TIME_WAIT,
|
| 156 |
+
"07": _common.CONN_CLOSE,
|
| 157 |
+
"08": _common.CONN_CLOSE_WAIT,
|
| 158 |
+
"09": _common.CONN_LAST_ACK,
|
| 159 |
+
"0A": _common.CONN_LISTEN,
|
| 160 |
+
"0B": _common.CONN_CLOSING,
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
# =====================================================================
|
| 165 |
+
# --- named tuples
|
| 166 |
+
# =====================================================================
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
# fmt: off
|
| 170 |
+
# psutil.virtual_memory()
|
| 171 |
+
svmem = namedtuple(
|
| 172 |
+
'svmem', ['total', 'available', 'percent', 'used', 'free',
|
| 173 |
+
'active', 'inactive', 'buffers', 'cached', 'shared', 'slab'])
|
| 174 |
+
# psutil.disk_io_counters()
|
| 175 |
+
sdiskio = namedtuple(
|
| 176 |
+
'sdiskio', ['read_count', 'write_count',
|
| 177 |
+
'read_bytes', 'write_bytes',
|
| 178 |
+
'read_time', 'write_time',
|
| 179 |
+
'read_merged_count', 'write_merged_count',
|
| 180 |
+
'busy_time'])
|
| 181 |
+
# psutil.Process().open_files()
|
| 182 |
+
popenfile = namedtuple(
|
| 183 |
+
'popenfile', ['path', 'fd', 'position', 'mode', 'flags'])
|
| 184 |
+
# psutil.Process().memory_info()
|
| 185 |
+
pmem = namedtuple('pmem', 'rss vms shared text lib data dirty')
|
| 186 |
+
# psutil.Process().memory_full_info()
|
| 187 |
+
pfullmem = namedtuple('pfullmem', pmem._fields + ('uss', 'pss', 'swap'))
|
| 188 |
+
# psutil.Process().memory_maps(grouped=True)
|
| 189 |
+
pmmap_grouped = namedtuple(
|
| 190 |
+
'pmmap_grouped',
|
| 191 |
+
['path', 'rss', 'size', 'pss', 'shared_clean', 'shared_dirty',
|
| 192 |
+
'private_clean', 'private_dirty', 'referenced', 'anonymous', 'swap'])
|
| 193 |
+
# psutil.Process().memory_maps(grouped=False)
|
| 194 |
+
pmmap_ext = namedtuple(
|
| 195 |
+
'pmmap_ext', 'addr perms ' + ' '.join(pmmap_grouped._fields))
|
| 196 |
+
# psutil.Process.io_counters()
|
| 197 |
+
pio = namedtuple('pio', ['read_count', 'write_count',
|
| 198 |
+
'read_bytes', 'write_bytes',
|
| 199 |
+
'read_chars', 'write_chars'])
|
| 200 |
+
# psutil.Process.cpu_times()
|
| 201 |
+
pcputimes = namedtuple('pcputimes',
|
| 202 |
+
['user', 'system', 'children_user', 'children_system',
|
| 203 |
+
'iowait'])
|
| 204 |
+
# fmt: on
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
# =====================================================================
|
| 208 |
+
# --- utils
|
| 209 |
+
# =====================================================================
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def readlink(path):
|
| 213 |
+
"""Wrapper around os.readlink()."""
|
| 214 |
+
assert isinstance(path, basestring), path
|
| 215 |
+
path = os.readlink(path)
|
| 216 |
+
# readlink() might return paths containing null bytes ('\x00')
|
| 217 |
+
# resulting in "TypeError: must be encoded string without NULL
|
| 218 |
+
# bytes, not str" errors when the string is passed to other
|
| 219 |
+
# fs-related functions (os.*, open(), ...).
|
| 220 |
+
# Apparently everything after '\x00' is garbage (we can have
|
| 221 |
+
# ' (deleted)', 'new' and possibly others), see:
|
| 222 |
+
# https://github.com/giampaolo/psutil/issues/717
|
| 223 |
+
path = path.split('\x00')[0]
|
| 224 |
+
# Certain paths have ' (deleted)' appended. Usually this is
|
| 225 |
+
# bogus as the file actually exists. Even if it doesn't we
|
| 226 |
+
# don't care.
|
| 227 |
+
if path.endswith(' (deleted)') and not path_exists_strict(path):
|
| 228 |
+
path = path[:-10]
|
| 229 |
+
return path
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def file_flags_to_mode(flags):
|
| 233 |
+
"""Convert file's open() flags into a readable string.
|
| 234 |
+
Used by Process.open_files().
|
| 235 |
+
"""
|
| 236 |
+
modes_map = {os.O_RDONLY: 'r', os.O_WRONLY: 'w', os.O_RDWR: 'w+'}
|
| 237 |
+
mode = modes_map[flags & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)]
|
| 238 |
+
if flags & os.O_APPEND:
|
| 239 |
+
mode = mode.replace('w', 'a', 1)
|
| 240 |
+
mode = mode.replace('w+', 'r+')
|
| 241 |
+
# possible values: r, w, a, r+, a+
|
| 242 |
+
return mode
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def is_storage_device(name):
|
| 246 |
+
"""Return True if the given name refers to a root device (e.g.
|
| 247 |
+
"sda", "nvme0n1") as opposed to a logical partition (e.g. "sda1",
|
| 248 |
+
"nvme0n1p1"). If name is a virtual device (e.g. "loop1", "ram")
|
| 249 |
+
return True.
|
| 250 |
+
"""
|
| 251 |
+
# Re-adapted from iostat source code, see:
|
| 252 |
+
# https://github.com/sysstat/sysstat/blob/
|
| 253 |
+
# 97912938cd476645b267280069e83b1c8dc0e1c7/common.c#L208
|
| 254 |
+
# Some devices may have a slash in their name (e.g. cciss/c0d0...).
|
| 255 |
+
name = name.replace('/', '!')
|
| 256 |
+
including_virtual = True
|
| 257 |
+
if including_virtual:
|
| 258 |
+
path = "/sys/block/%s" % name
|
| 259 |
+
else:
|
| 260 |
+
path = "/sys/block/%s/device" % name
|
| 261 |
+
return os.access(path, os.F_OK)
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
@memoize
|
| 265 |
+
def set_scputimes_ntuple(procfs_path):
|
| 266 |
+
"""Set a namedtuple of variable fields depending on the CPU times
|
| 267 |
+
available on this Linux kernel version which may be:
|
| 268 |
+
(user, nice, system, idle, iowait, irq, softirq, [steal, [guest,
|
| 269 |
+
[guest_nice]]])
|
| 270 |
+
Used by cpu_times() function.
|
| 271 |
+
"""
|
| 272 |
+
global scputimes
|
| 273 |
+
with open_binary('%s/stat' % procfs_path) as f:
|
| 274 |
+
values = f.readline().split()[1:]
|
| 275 |
+
fields = ['user', 'nice', 'system', 'idle', 'iowait', 'irq', 'softirq']
|
| 276 |
+
vlen = len(values)
|
| 277 |
+
if vlen >= 8:
|
| 278 |
+
# Linux >= 2.6.11
|
| 279 |
+
fields.append('steal')
|
| 280 |
+
if vlen >= 9:
|
| 281 |
+
# Linux >= 2.6.24
|
| 282 |
+
fields.append('guest')
|
| 283 |
+
if vlen >= 10:
|
| 284 |
+
# Linux >= 3.2.0
|
| 285 |
+
fields.append('guest_nice')
|
| 286 |
+
scputimes = namedtuple('scputimes', fields)
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
try:
|
| 290 |
+
set_scputimes_ntuple("/proc")
|
| 291 |
+
except Exception as err: # noqa: BLE001
|
| 292 |
+
# Don't want to crash at import time.
|
| 293 |
+
debug("ignoring exception on import: %r" % err)
|
| 294 |
+
scputimes = namedtuple('scputimes', 'user system idle')(0.0, 0.0, 0.0)
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
# =====================================================================
|
| 298 |
+
# --- prlimit
|
| 299 |
+
# =====================================================================
|
| 300 |
+
|
| 301 |
+
# Backport of resource.prlimit() for Python 2. Originally this was done
|
| 302 |
+
# in C, but CentOS-6 which we use to create manylinux wheels is too old
|
| 303 |
+
# and does not support prlimit() syscall. As such the resulting wheel
|
| 304 |
+
# would not include prlimit(), even when installed on newer systems.
|
| 305 |
+
# This is the only part of psutil using ctypes.
|
| 306 |
+
|
| 307 |
+
prlimit = None
|
| 308 |
+
try:
|
| 309 |
+
from resource import prlimit # python >= 3.4
|
| 310 |
+
except ImportError:
|
| 311 |
+
import ctypes
|
| 312 |
+
|
| 313 |
+
libc = ctypes.CDLL(None, use_errno=True)
|
| 314 |
+
|
| 315 |
+
if hasattr(libc, "prlimit"):
|
| 316 |
+
|
| 317 |
+
def prlimit(pid, resource_, limits=None):
|
| 318 |
+
class StructRlimit(ctypes.Structure):
|
| 319 |
+
_fields_ = [
|
| 320 |
+
('rlim_cur', ctypes.c_longlong),
|
| 321 |
+
('rlim_max', ctypes.c_longlong),
|
| 322 |
+
]
|
| 323 |
+
|
| 324 |
+
current = StructRlimit()
|
| 325 |
+
if limits is None:
|
| 326 |
+
# get
|
| 327 |
+
ret = libc.prlimit(pid, resource_, None, ctypes.byref(current))
|
| 328 |
+
else:
|
| 329 |
+
# set
|
| 330 |
+
new = StructRlimit()
|
| 331 |
+
new.rlim_cur = limits[0]
|
| 332 |
+
new.rlim_max = limits[1]
|
| 333 |
+
ret = libc.prlimit(
|
| 334 |
+
pid, resource_, ctypes.byref(new), ctypes.byref(current)
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
if ret != 0:
|
| 338 |
+
errno_ = ctypes.get_errno()
|
| 339 |
+
raise OSError(errno_, os.strerror(errno_))
|
| 340 |
+
return (current.rlim_cur, current.rlim_max)
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
if prlimit is not None:
|
| 344 |
+
__extra__all__.extend(
|
| 345 |
+
[x for x in dir(cext) if x.startswith('RLIM') and x.isupper()]
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
# =====================================================================
|
| 350 |
+
# --- system memory
|
| 351 |
+
# =====================================================================
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def calculate_avail_vmem(mems):
|
| 355 |
+
"""Fallback for kernels < 3.14 where /proc/meminfo does not provide
|
| 356 |
+
"MemAvailable", see:
|
| 357 |
+
https://blog.famzah.net/2014/09/24/.
|
| 358 |
+
|
| 359 |
+
This code reimplements the algorithm outlined here:
|
| 360 |
+
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
|
| 361 |
+
commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
|
| 362 |
+
|
| 363 |
+
We use this function also when "MemAvailable" returns 0 (possibly a
|
| 364 |
+
kernel bug, see: https://github.com/giampaolo/psutil/issues/1915).
|
| 365 |
+
In that case this routine matches "free" CLI tool result ("available"
|
| 366 |
+
column).
|
| 367 |
+
|
| 368 |
+
XXX: on recent kernels this calculation may differ by ~1.5% compared
|
| 369 |
+
to "MemAvailable:", as it's calculated slightly differently.
|
| 370 |
+
It is still way more realistic than doing (free + cached) though.
|
| 371 |
+
See:
|
| 372 |
+
* https://gitlab.com/procps-ng/procps/issues/42
|
| 373 |
+
* https://github.com/famzah/linux-memavailable-procfs/issues/2
|
| 374 |
+
"""
|
| 375 |
+
# Note about "fallback" value. According to:
|
| 376 |
+
# https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
|
| 377 |
+
# commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
|
| 378 |
+
# ...long ago "available" memory was calculated as (free + cached),
|
| 379 |
+
# We use fallback when one of these is missing from /proc/meminfo:
|
| 380 |
+
# "Active(file)": introduced in 2.6.28 / Dec 2008
|
| 381 |
+
# "Inactive(file)": introduced in 2.6.28 / Dec 2008
|
| 382 |
+
# "SReclaimable": introduced in 2.6.19 / Nov 2006
|
| 383 |
+
# /proc/zoneinfo: introduced in 2.6.13 / Aug 2005
|
| 384 |
+
free = mems[b'MemFree:']
|
| 385 |
+
fallback = free + mems.get(b"Cached:", 0)
|
| 386 |
+
try:
|
| 387 |
+
lru_active_file = mems[b'Active(file):']
|
| 388 |
+
lru_inactive_file = mems[b'Inactive(file):']
|
| 389 |
+
slab_reclaimable = mems[b'SReclaimable:']
|
| 390 |
+
except KeyError as err:
|
| 391 |
+
debug(
|
| 392 |
+
"%s is missing from /proc/meminfo; using an approximation for "
|
| 393 |
+
"calculating available memory"
|
| 394 |
+
% err.args[0]
|
| 395 |
+
)
|
| 396 |
+
return fallback
|
| 397 |
+
try:
|
| 398 |
+
f = open_binary('%s/zoneinfo' % get_procfs_path())
|
| 399 |
+
except IOError:
|
| 400 |
+
return fallback # kernel 2.6.13
|
| 401 |
+
|
| 402 |
+
watermark_low = 0
|
| 403 |
+
with f:
|
| 404 |
+
for line in f:
|
| 405 |
+
line = line.strip()
|
| 406 |
+
if line.startswith(b'low'):
|
| 407 |
+
watermark_low += int(line.split()[1])
|
| 408 |
+
watermark_low *= PAGESIZE
|
| 409 |
+
|
| 410 |
+
avail = free - watermark_low
|
| 411 |
+
pagecache = lru_active_file + lru_inactive_file
|
| 412 |
+
pagecache -= min(pagecache / 2, watermark_low)
|
| 413 |
+
avail += pagecache
|
| 414 |
+
avail += slab_reclaimable - min(slab_reclaimable / 2.0, watermark_low)
|
| 415 |
+
return int(avail)
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
def virtual_memory():
|
| 419 |
+
"""Report virtual memory stats.
|
| 420 |
+
This implementation mimics procps-ng-3.3.12, aka "free" CLI tool:
|
| 421 |
+
https://gitlab.com/procps-ng/procps/blob/
|
| 422 |
+
24fd2605c51fccc375ab0287cec33aa767f06718/proc/sysinfo.c#L778-791
|
| 423 |
+
The returned values are supposed to match both "free" and "vmstat -s"
|
| 424 |
+
CLI tools.
|
| 425 |
+
"""
|
| 426 |
+
missing_fields = []
|
| 427 |
+
mems = {}
|
| 428 |
+
with open_binary('%s/meminfo' % get_procfs_path()) as f:
|
| 429 |
+
for line in f:
|
| 430 |
+
fields = line.split()
|
| 431 |
+
mems[fields[0]] = int(fields[1]) * 1024
|
| 432 |
+
|
| 433 |
+
# /proc doc states that the available fields in /proc/meminfo vary
|
| 434 |
+
# by architecture and compile options, but these 3 values are also
|
| 435 |
+
# returned by sysinfo(2); as such we assume they are always there.
|
| 436 |
+
total = mems[b'MemTotal:']
|
| 437 |
+
free = mems[b'MemFree:']
|
| 438 |
+
try:
|
| 439 |
+
buffers = mems[b'Buffers:']
|
| 440 |
+
except KeyError:
|
| 441 |
+
# https://github.com/giampaolo/psutil/issues/1010
|
| 442 |
+
buffers = 0
|
| 443 |
+
missing_fields.append('buffers')
|
| 444 |
+
try:
|
| 445 |
+
cached = mems[b"Cached:"]
|
| 446 |
+
except KeyError:
|
| 447 |
+
cached = 0
|
| 448 |
+
missing_fields.append('cached')
|
| 449 |
+
else:
|
| 450 |
+
# "free" cmdline utility sums reclaimable to cached.
|
| 451 |
+
# Older versions of procps used to add slab memory instead.
|
| 452 |
+
# This got changed in:
|
| 453 |
+
# https://gitlab.com/procps-ng/procps/commit/
|
| 454 |
+
# 05d751c4f076a2f0118b914c5e51cfbb4762ad8e
|
| 455 |
+
cached += mems.get(b"SReclaimable:", 0) # since kernel 2.6.19
|
| 456 |
+
|
| 457 |
+
try:
|
| 458 |
+
shared = mems[b'Shmem:'] # since kernel 2.6.32
|
| 459 |
+
except KeyError:
|
| 460 |
+
try:
|
| 461 |
+
shared = mems[b'MemShared:'] # kernels 2.4
|
| 462 |
+
except KeyError:
|
| 463 |
+
shared = 0
|
| 464 |
+
missing_fields.append('shared')
|
| 465 |
+
|
| 466 |
+
try:
|
| 467 |
+
active = mems[b"Active:"]
|
| 468 |
+
except KeyError:
|
| 469 |
+
active = 0
|
| 470 |
+
missing_fields.append('active')
|
| 471 |
+
|
| 472 |
+
try:
|
| 473 |
+
inactive = mems[b"Inactive:"]
|
| 474 |
+
except KeyError:
|
| 475 |
+
try:
|
| 476 |
+
inactive = (
|
| 477 |
+
mems[b"Inact_dirty:"]
|
| 478 |
+
+ mems[b"Inact_clean:"]
|
| 479 |
+
+ mems[b"Inact_laundry:"]
|
| 480 |
+
)
|
| 481 |
+
except KeyError:
|
| 482 |
+
inactive = 0
|
| 483 |
+
missing_fields.append('inactive')
|
| 484 |
+
|
| 485 |
+
try:
|
| 486 |
+
slab = mems[b"Slab:"]
|
| 487 |
+
except KeyError:
|
| 488 |
+
slab = 0
|
| 489 |
+
|
| 490 |
+
used = total - free - cached - buffers
|
| 491 |
+
if used < 0:
|
| 492 |
+
# May be symptomatic of running within a LCX container where such
|
| 493 |
+
# values will be dramatically distorted over those of the host.
|
| 494 |
+
used = total - free
|
| 495 |
+
|
| 496 |
+
# - starting from 4.4.0 we match free's "available" column.
|
| 497 |
+
# Before 4.4.0 we calculated it as (free + buffers + cached)
|
| 498 |
+
# which matched htop.
|
| 499 |
+
# - free and htop available memory differs as per:
|
| 500 |
+
# http://askubuntu.com/a/369589
|
| 501 |
+
# http://unix.stackexchange.com/a/65852/168884
|
| 502 |
+
# - MemAvailable has been introduced in kernel 3.14
|
| 503 |
+
try:
|
| 504 |
+
avail = mems[b'MemAvailable:']
|
| 505 |
+
except KeyError:
|
| 506 |
+
avail = calculate_avail_vmem(mems)
|
| 507 |
+
else:
|
| 508 |
+
if avail == 0:
|
| 509 |
+
# Yes, it can happen (probably a kernel bug):
|
| 510 |
+
# https://github.com/giampaolo/psutil/issues/1915
|
| 511 |
+
# In this case "free" CLI tool makes an estimate. We do the same,
|
| 512 |
+
# and it matches "free" CLI tool.
|
| 513 |
+
avail = calculate_avail_vmem(mems)
|
| 514 |
+
|
| 515 |
+
if avail < 0:
|
| 516 |
+
avail = 0
|
| 517 |
+
missing_fields.append('available')
|
| 518 |
+
elif avail > total:
|
| 519 |
+
# If avail is greater than total or our calculation overflows,
|
| 520 |
+
# that's symptomatic of running within a LCX container where such
|
| 521 |
+
# values will be dramatically distorted over those of the host.
|
| 522 |
+
# https://gitlab.com/procps-ng/procps/blob/
|
| 523 |
+
# 24fd2605c51fccc375ab0287cec33aa767f06718/proc/sysinfo.c#L764
|
| 524 |
+
avail = free
|
| 525 |
+
|
| 526 |
+
percent = usage_percent((total - avail), total, round_=1)
|
| 527 |
+
|
| 528 |
+
# Warn about missing metrics which are set to 0.
|
| 529 |
+
if missing_fields:
|
| 530 |
+
msg = "%s memory stats couldn't be determined and %s set to 0" % (
|
| 531 |
+
", ".join(missing_fields),
|
| 532 |
+
"was" if len(missing_fields) == 1 else "were",
|
| 533 |
+
)
|
| 534 |
+
warnings.warn(msg, RuntimeWarning, stacklevel=2)
|
| 535 |
+
|
| 536 |
+
return svmem(
|
| 537 |
+
total,
|
| 538 |
+
avail,
|
| 539 |
+
percent,
|
| 540 |
+
used,
|
| 541 |
+
free,
|
| 542 |
+
active,
|
| 543 |
+
inactive,
|
| 544 |
+
buffers,
|
| 545 |
+
cached,
|
| 546 |
+
shared,
|
| 547 |
+
slab,
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
def swap_memory():
|
| 552 |
+
"""Return swap memory metrics."""
|
| 553 |
+
mems = {}
|
| 554 |
+
with open_binary('%s/meminfo' % get_procfs_path()) as f:
|
| 555 |
+
for line in f:
|
| 556 |
+
fields = line.split()
|
| 557 |
+
mems[fields[0]] = int(fields[1]) * 1024
|
| 558 |
+
# We prefer /proc/meminfo over sysinfo() syscall so that
|
| 559 |
+
# psutil.PROCFS_PATH can be used in order to allow retrieval
|
| 560 |
+
# for linux containers, see:
|
| 561 |
+
# https://github.com/giampaolo/psutil/issues/1015
|
| 562 |
+
try:
|
| 563 |
+
total = mems[b'SwapTotal:']
|
| 564 |
+
free = mems[b'SwapFree:']
|
| 565 |
+
except KeyError:
|
| 566 |
+
_, _, _, _, total, free, unit_multiplier = cext.linux_sysinfo()
|
| 567 |
+
total *= unit_multiplier
|
| 568 |
+
free *= unit_multiplier
|
| 569 |
+
|
| 570 |
+
used = total - free
|
| 571 |
+
percent = usage_percent(used, total, round_=1)
|
| 572 |
+
# get pgin/pgouts
|
| 573 |
+
try:
|
| 574 |
+
f = open_binary("%s/vmstat" % get_procfs_path())
|
| 575 |
+
except IOError as err:
|
| 576 |
+
# see https://github.com/giampaolo/psutil/issues/722
|
| 577 |
+
msg = (
|
| 578 |
+
"'sin' and 'sout' swap memory stats couldn't "
|
| 579 |
+
+ "be determined and were set to 0 (%s)" % str(err)
|
| 580 |
+
)
|
| 581 |
+
warnings.warn(msg, RuntimeWarning, stacklevel=2)
|
| 582 |
+
sin = sout = 0
|
| 583 |
+
else:
|
| 584 |
+
with f:
|
| 585 |
+
sin = sout = None
|
| 586 |
+
for line in f:
|
| 587 |
+
# values are expressed in 4 kilo bytes, we want
|
| 588 |
+
# bytes instead
|
| 589 |
+
if line.startswith(b'pswpin'):
|
| 590 |
+
sin = int(line.split(b' ')[1]) * 4 * 1024
|
| 591 |
+
elif line.startswith(b'pswpout'):
|
| 592 |
+
sout = int(line.split(b' ')[1]) * 4 * 1024
|
| 593 |
+
if sin is not None and sout is not None:
|
| 594 |
+
break
|
| 595 |
+
else:
|
| 596 |
+
# we might get here when dealing with exotic Linux
|
| 597 |
+
# flavors, see:
|
| 598 |
+
# https://github.com/giampaolo/psutil/issues/313
|
| 599 |
+
msg = "'sin' and 'sout' swap memory stats couldn't "
|
| 600 |
+
msg += "be determined and were set to 0"
|
| 601 |
+
warnings.warn(msg, RuntimeWarning, stacklevel=2)
|
| 602 |
+
sin = sout = 0
|
| 603 |
+
return _common.sswap(total, used, free, percent, sin, sout)
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
# =====================================================================
|
| 607 |
+
# --- CPU
|
| 608 |
+
# =====================================================================
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
def cpu_times():
|
| 612 |
+
"""Return a named tuple representing the following system-wide
|
| 613 |
+
CPU times:
|
| 614 |
+
(user, nice, system, idle, iowait, irq, softirq [steal, [guest,
|
| 615 |
+
[guest_nice]]])
|
| 616 |
+
Last 3 fields may not be available on all Linux kernel versions.
|
| 617 |
+
"""
|
| 618 |
+
procfs_path = get_procfs_path()
|
| 619 |
+
set_scputimes_ntuple(procfs_path)
|
| 620 |
+
with open_binary('%s/stat' % procfs_path) as f:
|
| 621 |
+
values = f.readline().split()
|
| 622 |
+
fields = values[1 : len(scputimes._fields) + 1]
|
| 623 |
+
fields = [float(x) / CLOCK_TICKS for x in fields]
|
| 624 |
+
return scputimes(*fields)
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
def per_cpu_times():
|
| 628 |
+
"""Return a list of namedtuple representing the CPU times
|
| 629 |
+
for every CPU available on the system.
|
| 630 |
+
"""
|
| 631 |
+
procfs_path = get_procfs_path()
|
| 632 |
+
set_scputimes_ntuple(procfs_path)
|
| 633 |
+
cpus = []
|
| 634 |
+
with open_binary('%s/stat' % procfs_path) as f:
|
| 635 |
+
# get rid of the first line which refers to system wide CPU stats
|
| 636 |
+
f.readline()
|
| 637 |
+
for line in f:
|
| 638 |
+
if line.startswith(b'cpu'):
|
| 639 |
+
values = line.split()
|
| 640 |
+
fields = values[1 : len(scputimes._fields) + 1]
|
| 641 |
+
fields = [float(x) / CLOCK_TICKS for x in fields]
|
| 642 |
+
entry = scputimes(*fields)
|
| 643 |
+
cpus.append(entry)
|
| 644 |
+
return cpus
|
| 645 |
+
|
| 646 |
+
|
| 647 |
+
def cpu_count_logical():
|
| 648 |
+
"""Return the number of logical CPUs in the system."""
|
| 649 |
+
try:
|
| 650 |
+
return os.sysconf("SC_NPROCESSORS_ONLN")
|
| 651 |
+
except ValueError:
|
| 652 |
+
# as a second fallback we try to parse /proc/cpuinfo
|
| 653 |
+
num = 0
|
| 654 |
+
with open_binary('%s/cpuinfo' % get_procfs_path()) as f:
|
| 655 |
+
for line in f:
|
| 656 |
+
if line.lower().startswith(b'processor'):
|
| 657 |
+
num += 1
|
| 658 |
+
|
| 659 |
+
# unknown format (e.g. amrel/sparc architectures), see:
|
| 660 |
+
# https://github.com/giampaolo/psutil/issues/200
|
| 661 |
+
# try to parse /proc/stat as a last resort
|
| 662 |
+
if num == 0:
|
| 663 |
+
search = re.compile(r'cpu\d')
|
| 664 |
+
with open_text('%s/stat' % get_procfs_path()) as f:
|
| 665 |
+
for line in f:
|
| 666 |
+
line = line.split(' ')[0]
|
| 667 |
+
if search.match(line):
|
| 668 |
+
num += 1
|
| 669 |
+
|
| 670 |
+
if num == 0:
|
| 671 |
+
# mimic os.cpu_count()
|
| 672 |
+
return None
|
| 673 |
+
return num
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
def cpu_count_cores():
|
| 677 |
+
"""Return the number of CPU cores in the system."""
|
| 678 |
+
# Method #1
|
| 679 |
+
ls = set()
|
| 680 |
+
# These 2 files are the same but */core_cpus_list is newer while
|
| 681 |
+
# */thread_siblings_list is deprecated and may disappear in the future.
|
| 682 |
+
# https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst
|
| 683 |
+
# https://github.com/giampaolo/psutil/pull/1727#issuecomment-707624964
|
| 684 |
+
# https://lkml.org/lkml/2019/2/26/41
|
| 685 |
+
p1 = "/sys/devices/system/cpu/cpu[0-9]*/topology/core_cpus_list"
|
| 686 |
+
p2 = "/sys/devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list"
|
| 687 |
+
for path in glob.glob(p1) or glob.glob(p2):
|
| 688 |
+
with open_binary(path) as f:
|
| 689 |
+
ls.add(f.read().strip())
|
| 690 |
+
result = len(ls)
|
| 691 |
+
if result != 0:
|
| 692 |
+
return result
|
| 693 |
+
|
| 694 |
+
# Method #2
|
| 695 |
+
mapping = {}
|
| 696 |
+
current_info = {}
|
| 697 |
+
with open_binary('%s/cpuinfo' % get_procfs_path()) as f:
|
| 698 |
+
for line in f:
|
| 699 |
+
line = line.strip().lower()
|
| 700 |
+
if not line:
|
| 701 |
+
# new section
|
| 702 |
+
try:
|
| 703 |
+
mapping[current_info[b'physical id']] = current_info[
|
| 704 |
+
b'cpu cores'
|
| 705 |
+
]
|
| 706 |
+
except KeyError:
|
| 707 |
+
pass
|
| 708 |
+
current_info = {}
|
| 709 |
+
elif line.startswith((b'physical id', b'cpu cores')):
|
| 710 |
+
# ongoing section
|
| 711 |
+
key, value = line.split(b'\t:', 1)
|
| 712 |
+
current_info[key] = int(value)
|
| 713 |
+
|
| 714 |
+
result = sum(mapping.values())
|
| 715 |
+
return result or None # mimic os.cpu_count()
|
| 716 |
+
|
| 717 |
+
|
| 718 |
+
def cpu_stats():
|
| 719 |
+
"""Return various CPU stats as a named tuple."""
|
| 720 |
+
with open_binary('%s/stat' % get_procfs_path()) as f:
|
| 721 |
+
ctx_switches = None
|
| 722 |
+
interrupts = None
|
| 723 |
+
soft_interrupts = None
|
| 724 |
+
for line in f:
|
| 725 |
+
if line.startswith(b'ctxt'):
|
| 726 |
+
ctx_switches = int(line.split()[1])
|
| 727 |
+
elif line.startswith(b'intr'):
|
| 728 |
+
interrupts = int(line.split()[1])
|
| 729 |
+
elif line.startswith(b'softirq'):
|
| 730 |
+
soft_interrupts = int(line.split()[1])
|
| 731 |
+
if (
|
| 732 |
+
ctx_switches is not None
|
| 733 |
+
and soft_interrupts is not None
|
| 734 |
+
and interrupts is not None
|
| 735 |
+
):
|
| 736 |
+
break
|
| 737 |
+
syscalls = 0
|
| 738 |
+
return _common.scpustats(
|
| 739 |
+
ctx_switches, interrupts, soft_interrupts, syscalls
|
| 740 |
+
)
|
| 741 |
+
|
| 742 |
+
|
| 743 |
+
def _cpu_get_cpuinfo_freq():
|
| 744 |
+
"""Return current CPU frequency from cpuinfo if available."""
|
| 745 |
+
ret = []
|
| 746 |
+
with open_binary('%s/cpuinfo' % get_procfs_path()) as f:
|
| 747 |
+
for line in f:
|
| 748 |
+
if line.lower().startswith(b'cpu mhz'):
|
| 749 |
+
ret.append(float(line.split(b':', 1)[1]))
|
| 750 |
+
return ret
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
if os.path.exists("/sys/devices/system/cpu/cpufreq/policy0") or os.path.exists(
|
| 754 |
+
"/sys/devices/system/cpu/cpu0/cpufreq"
|
| 755 |
+
):
|
| 756 |
+
|
| 757 |
+
def cpu_freq():
|
| 758 |
+
"""Return frequency metrics for all CPUs.
|
| 759 |
+
Contrarily to other OSes, Linux updates these values in
|
| 760 |
+
real-time.
|
| 761 |
+
"""
|
| 762 |
+
cpuinfo_freqs = _cpu_get_cpuinfo_freq()
|
| 763 |
+
paths = glob.glob(
|
| 764 |
+
"/sys/devices/system/cpu/cpufreq/policy[0-9]*"
|
| 765 |
+
) or glob.glob("/sys/devices/system/cpu/cpu[0-9]*/cpufreq")
|
| 766 |
+
paths.sort(key=lambda x: int(re.search(r"[0-9]+", x).group()))
|
| 767 |
+
ret = []
|
| 768 |
+
pjoin = os.path.join
|
| 769 |
+
for i, path in enumerate(paths):
|
| 770 |
+
if len(paths) == len(cpuinfo_freqs):
|
| 771 |
+
# take cached value from cpuinfo if available, see:
|
| 772 |
+
# https://github.com/giampaolo/psutil/issues/1851
|
| 773 |
+
curr = cpuinfo_freqs[i] * 1000
|
| 774 |
+
else:
|
| 775 |
+
curr = bcat(pjoin(path, "scaling_cur_freq"), fallback=None)
|
| 776 |
+
if curr is None:
|
| 777 |
+
# Likely an old RedHat, see:
|
| 778 |
+
# https://github.com/giampaolo/psutil/issues/1071
|
| 779 |
+
curr = bcat(pjoin(path, "cpuinfo_cur_freq"), fallback=None)
|
| 780 |
+
if curr is None:
|
| 781 |
+
online_path = (
|
| 782 |
+
"/sys/devices/system/cpu/cpu{}/online".format(i)
|
| 783 |
+
)
|
| 784 |
+
# if cpu core is offline, set to all zeroes
|
| 785 |
+
if cat(online_path, fallback=None) == "0\n":
|
| 786 |
+
ret.append(_common.scpufreq(0.0, 0.0, 0.0))
|
| 787 |
+
continue
|
| 788 |
+
msg = "can't find current frequency file"
|
| 789 |
+
raise NotImplementedError(msg)
|
| 790 |
+
curr = int(curr) / 1000
|
| 791 |
+
max_ = int(bcat(pjoin(path, "scaling_max_freq"))) / 1000
|
| 792 |
+
min_ = int(bcat(pjoin(path, "scaling_min_freq"))) / 1000
|
| 793 |
+
ret.append(_common.scpufreq(curr, min_, max_))
|
| 794 |
+
return ret
|
| 795 |
+
|
| 796 |
+
else:
|
| 797 |
+
|
| 798 |
+
def cpu_freq():
|
| 799 |
+
"""Alternate implementation using /proc/cpuinfo.
|
| 800 |
+
min and max frequencies are not available and are set to None.
|
| 801 |
+
"""
|
| 802 |
+
return [_common.scpufreq(x, 0.0, 0.0) for x in _cpu_get_cpuinfo_freq()]
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
# =====================================================================
|
| 806 |
+
# --- network
|
| 807 |
+
# =====================================================================
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
net_if_addrs = cext_posix.net_if_addrs
|
| 811 |
+
|
| 812 |
+
|
| 813 |
+
class _Ipv6UnsupportedError(Exception):
|
| 814 |
+
pass
|
| 815 |
+
|
| 816 |
+
|
| 817 |
+
class NetConnections:
|
| 818 |
+
"""A wrapper on top of /proc/net/* files, retrieving per-process
|
| 819 |
+
and system-wide open connections (TCP, UDP, UNIX) similarly to
|
| 820 |
+
"netstat -an".
|
| 821 |
+
|
| 822 |
+
Note: in case of UNIX sockets we're only able to determine the
|
| 823 |
+
local endpoint/path, not the one it's connected to.
|
| 824 |
+
According to [1] it would be possible but not easily.
|
| 825 |
+
|
| 826 |
+
[1] http://serverfault.com/a/417946
|
| 827 |
+
"""
|
| 828 |
+
|
| 829 |
+
def __init__(self):
|
| 830 |
+
# The string represents the basename of the corresponding
|
| 831 |
+
# /proc/net/{proto_name} file.
|
| 832 |
+
tcp4 = ("tcp", socket.AF_INET, socket.SOCK_STREAM)
|
| 833 |
+
tcp6 = ("tcp6", socket.AF_INET6, socket.SOCK_STREAM)
|
| 834 |
+
udp4 = ("udp", socket.AF_INET, socket.SOCK_DGRAM)
|
| 835 |
+
udp6 = ("udp6", socket.AF_INET6, socket.SOCK_DGRAM)
|
| 836 |
+
unix = ("unix", socket.AF_UNIX, None)
|
| 837 |
+
self.tmap = {
|
| 838 |
+
"all": (tcp4, tcp6, udp4, udp6, unix),
|
| 839 |
+
"tcp": (tcp4, tcp6),
|
| 840 |
+
"tcp4": (tcp4,),
|
| 841 |
+
"tcp6": (tcp6,),
|
| 842 |
+
"udp": (udp4, udp6),
|
| 843 |
+
"udp4": (udp4,),
|
| 844 |
+
"udp6": (udp6,),
|
| 845 |
+
"unix": (unix,),
|
| 846 |
+
"inet": (tcp4, tcp6, udp4, udp6),
|
| 847 |
+
"inet4": (tcp4, udp4),
|
| 848 |
+
"inet6": (tcp6, udp6),
|
| 849 |
+
}
|
| 850 |
+
self._procfs_path = None
|
| 851 |
+
|
| 852 |
+
def get_proc_inodes(self, pid):
|
| 853 |
+
inodes = defaultdict(list)
|
| 854 |
+
for fd in os.listdir("%s/%s/fd" % (self._procfs_path, pid)):
|
| 855 |
+
try:
|
| 856 |
+
inode = readlink("%s/%s/fd/%s" % (self._procfs_path, pid, fd))
|
| 857 |
+
except (FileNotFoundError, ProcessLookupError):
|
| 858 |
+
# ENOENT == file which is gone in the meantime;
|
| 859 |
+
# os.stat('/proc/%s' % self.pid) will be done later
|
| 860 |
+
# to force NSP (if it's the case)
|
| 861 |
+
continue
|
| 862 |
+
except OSError as err:
|
| 863 |
+
if err.errno == errno.EINVAL:
|
| 864 |
+
# not a link
|
| 865 |
+
continue
|
| 866 |
+
if err.errno == errno.ENAMETOOLONG:
|
| 867 |
+
# file name too long
|
| 868 |
+
debug(err)
|
| 869 |
+
continue
|
| 870 |
+
raise
|
| 871 |
+
else:
|
| 872 |
+
if inode.startswith('socket:['):
|
| 873 |
+
# the process is using a socket
|
| 874 |
+
inode = inode[8:][:-1]
|
| 875 |
+
inodes[inode].append((pid, int(fd)))
|
| 876 |
+
return inodes
|
| 877 |
+
|
| 878 |
+
def get_all_inodes(self):
|
| 879 |
+
inodes = {}
|
| 880 |
+
for pid in pids():
|
| 881 |
+
try:
|
| 882 |
+
inodes.update(self.get_proc_inodes(pid))
|
| 883 |
+
except (FileNotFoundError, ProcessLookupError, PermissionError):
|
| 884 |
+
# os.listdir() is gonna raise a lot of access denied
|
| 885 |
+
# exceptions in case of unprivileged user; that's fine
|
| 886 |
+
# as we'll just end up returning a connection with PID
|
| 887 |
+
# and fd set to None anyway.
|
| 888 |
+
# Both netstat -an and lsof does the same so it's
|
| 889 |
+
# unlikely we can do any better.
|
| 890 |
+
# ENOENT just means a PID disappeared on us.
|
| 891 |
+
continue
|
| 892 |
+
return inodes
|
| 893 |
+
|
| 894 |
+
@staticmethod
|
| 895 |
+
def decode_address(addr, family):
|
| 896 |
+
"""Accept an "ip:port" address as displayed in /proc/net/*
|
| 897 |
+
and convert it into a human readable form, like:
|
| 898 |
+
|
| 899 |
+
"0500000A:0016" -> ("10.0.0.5", 22)
|
| 900 |
+
"0000000000000000FFFF00000100007F:9E49" -> ("::ffff:127.0.0.1", 40521)
|
| 901 |
+
|
| 902 |
+
The IP address portion is a little or big endian four-byte
|
| 903 |
+
hexadecimal number; that is, the least significant byte is listed
|
| 904 |
+
first, so we need to reverse the order of the bytes to convert it
|
| 905 |
+
to an IP address.
|
| 906 |
+
The port is represented as a two-byte hexadecimal number.
|
| 907 |
+
|
| 908 |
+
Reference:
|
| 909 |
+
http://linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html
|
| 910 |
+
"""
|
| 911 |
+
ip, port = addr.split(':')
|
| 912 |
+
port = int(port, 16)
|
| 913 |
+
# this usually refers to a local socket in listen mode with
|
| 914 |
+
# no end-points connected
|
| 915 |
+
if not port:
|
| 916 |
+
return ()
|
| 917 |
+
if PY3:
|
| 918 |
+
ip = ip.encode('ascii')
|
| 919 |
+
if family == socket.AF_INET:
|
| 920 |
+
# see: https://github.com/giampaolo/psutil/issues/201
|
| 921 |
+
if LITTLE_ENDIAN:
|
| 922 |
+
ip = socket.inet_ntop(family, base64.b16decode(ip)[::-1])
|
| 923 |
+
else:
|
| 924 |
+
ip = socket.inet_ntop(family, base64.b16decode(ip))
|
| 925 |
+
else: # IPv6
|
| 926 |
+
ip = base64.b16decode(ip)
|
| 927 |
+
try:
|
| 928 |
+
# see: https://github.com/giampaolo/psutil/issues/201
|
| 929 |
+
if LITTLE_ENDIAN:
|
| 930 |
+
ip = socket.inet_ntop(
|
| 931 |
+
socket.AF_INET6,
|
| 932 |
+
struct.pack('>4I', *struct.unpack('<4I', ip)),
|
| 933 |
+
)
|
| 934 |
+
else:
|
| 935 |
+
ip = socket.inet_ntop(
|
| 936 |
+
socket.AF_INET6,
|
| 937 |
+
struct.pack('<4I', *struct.unpack('<4I', ip)),
|
| 938 |
+
)
|
| 939 |
+
except ValueError:
|
| 940 |
+
# see: https://github.com/giampaolo/psutil/issues/623
|
| 941 |
+
if not supports_ipv6():
|
| 942 |
+
raise _Ipv6UnsupportedError
|
| 943 |
+
else:
|
| 944 |
+
raise
|
| 945 |
+
return _common.addr(ip, port)
|
| 946 |
+
|
| 947 |
+
@staticmethod
|
| 948 |
+
def process_inet(file, family, type_, inodes, filter_pid=None):
|
| 949 |
+
"""Parse /proc/net/tcp* and /proc/net/udp* files."""
|
| 950 |
+
if file.endswith('6') and not os.path.exists(file):
|
| 951 |
+
# IPv6 not supported
|
| 952 |
+
return
|
| 953 |
+
with open_text(file) as f:
|
| 954 |
+
f.readline() # skip the first line
|
| 955 |
+
for lineno, line in enumerate(f, 1):
|
| 956 |
+
try:
|
| 957 |
+
_, laddr, raddr, status, _, _, _, _, _, inode = (
|
| 958 |
+
line.split()[:10]
|
| 959 |
+
)
|
| 960 |
+
except ValueError:
|
| 961 |
+
raise RuntimeError(
|
| 962 |
+
"error while parsing %s; malformed line %s %r"
|
| 963 |
+
% (file, lineno, line)
|
| 964 |
+
)
|
| 965 |
+
if inode in inodes:
|
| 966 |
+
# # We assume inet sockets are unique, so we error
|
| 967 |
+
# # out if there are multiple references to the
|
| 968 |
+
# # same inode. We won't do this for UNIX sockets.
|
| 969 |
+
# if len(inodes[inode]) > 1 and family != socket.AF_UNIX:
|
| 970 |
+
# raise ValueError("ambiguous inode with multiple "
|
| 971 |
+
# "PIDs references")
|
| 972 |
+
pid, fd = inodes[inode][0]
|
| 973 |
+
else:
|
| 974 |
+
pid, fd = None, -1
|
| 975 |
+
if filter_pid is not None and filter_pid != pid:
|
| 976 |
+
continue
|
| 977 |
+
else:
|
| 978 |
+
if type_ == socket.SOCK_STREAM:
|
| 979 |
+
status = TCP_STATUSES[status]
|
| 980 |
+
else:
|
| 981 |
+
status = _common.CONN_NONE
|
| 982 |
+
try:
|
| 983 |
+
laddr = NetConnections.decode_address(laddr, family)
|
| 984 |
+
raddr = NetConnections.decode_address(raddr, family)
|
| 985 |
+
except _Ipv6UnsupportedError:
|
| 986 |
+
continue
|
| 987 |
+
yield (fd, family, type_, laddr, raddr, status, pid)
|
| 988 |
+
|
| 989 |
+
@staticmethod
|
| 990 |
+
def process_unix(file, family, inodes, filter_pid=None):
|
| 991 |
+
"""Parse /proc/net/unix files."""
|
| 992 |
+
with open_text(file) as f:
|
| 993 |
+
f.readline() # skip the first line
|
| 994 |
+
for line in f:
|
| 995 |
+
tokens = line.split()
|
| 996 |
+
try:
|
| 997 |
+
_, _, _, _, type_, _, inode = tokens[0:7]
|
| 998 |
+
except ValueError:
|
| 999 |
+
if ' ' not in line:
|
| 1000 |
+
# see: https://github.com/giampaolo/psutil/issues/766
|
| 1001 |
+
continue
|
| 1002 |
+
raise RuntimeError(
|
| 1003 |
+
"error while parsing %s; malformed line %r"
|
| 1004 |
+
% (file, line)
|
| 1005 |
+
)
|
| 1006 |
+
if inode in inodes: # noqa
|
| 1007 |
+
# With UNIX sockets we can have a single inode
|
| 1008 |
+
# referencing many file descriptors.
|
| 1009 |
+
pairs = inodes[inode]
|
| 1010 |
+
else:
|
| 1011 |
+
pairs = [(None, -1)]
|
| 1012 |
+
for pid, fd in pairs:
|
| 1013 |
+
if filter_pid is not None and filter_pid != pid:
|
| 1014 |
+
continue
|
| 1015 |
+
else:
|
| 1016 |
+
path = tokens[-1] if len(tokens) == 8 else ''
|
| 1017 |
+
type_ = _common.socktype_to_enum(int(type_))
|
| 1018 |
+
# XXX: determining the remote endpoint of a
|
| 1019 |
+
# UNIX socket on Linux is not possible, see:
|
| 1020 |
+
# https://serverfault.com/questions/252723/
|
| 1021 |
+
raddr = ""
|
| 1022 |
+
status = _common.CONN_NONE
|
| 1023 |
+
yield (fd, family, type_, path, raddr, status, pid)
|
| 1024 |
+
|
| 1025 |
+
def retrieve(self, kind, pid=None):
|
| 1026 |
+
if kind not in self.tmap:
|
| 1027 |
+
raise ValueError(
|
| 1028 |
+
"invalid %r kind argument; choose between %s"
|
| 1029 |
+
% (kind, ', '.join([repr(x) for x in self.tmap]))
|
| 1030 |
+
)
|
| 1031 |
+
self._procfs_path = get_procfs_path()
|
| 1032 |
+
if pid is not None:
|
| 1033 |
+
inodes = self.get_proc_inodes(pid)
|
| 1034 |
+
if not inodes:
|
| 1035 |
+
# no connections for this process
|
| 1036 |
+
return []
|
| 1037 |
+
else:
|
| 1038 |
+
inodes = self.get_all_inodes()
|
| 1039 |
+
ret = set()
|
| 1040 |
+
for proto_name, family, type_ in self.tmap[kind]:
|
| 1041 |
+
path = "%s/net/%s" % (self._procfs_path, proto_name)
|
| 1042 |
+
if family in {socket.AF_INET, socket.AF_INET6}:
|
| 1043 |
+
ls = self.process_inet(
|
| 1044 |
+
path, family, type_, inodes, filter_pid=pid
|
| 1045 |
+
)
|
| 1046 |
+
else:
|
| 1047 |
+
ls = self.process_unix(path, family, inodes, filter_pid=pid)
|
| 1048 |
+
for fd, family, type_, laddr, raddr, status, bound_pid in ls:
|
| 1049 |
+
if pid:
|
| 1050 |
+
conn = _common.pconn(
|
| 1051 |
+
fd, family, type_, laddr, raddr, status
|
| 1052 |
+
)
|
| 1053 |
+
else:
|
| 1054 |
+
conn = _common.sconn(
|
| 1055 |
+
fd, family, type_, laddr, raddr, status, bound_pid
|
| 1056 |
+
)
|
| 1057 |
+
ret.add(conn)
|
| 1058 |
+
return list(ret)
|
| 1059 |
+
|
| 1060 |
+
|
| 1061 |
+
_net_connections = NetConnections()
|
| 1062 |
+
|
| 1063 |
+
|
| 1064 |
+
def net_connections(kind='inet'):
|
| 1065 |
+
"""Return system-wide open connections."""
|
| 1066 |
+
return _net_connections.retrieve(kind)
|
| 1067 |
+
|
| 1068 |
+
|
| 1069 |
+
def net_io_counters():
|
| 1070 |
+
"""Return network I/O statistics for every network interface
|
| 1071 |
+
installed on the system as a dict of raw tuples.
|
| 1072 |
+
"""
|
| 1073 |
+
with open_text("%s/net/dev" % get_procfs_path()) as f:
|
| 1074 |
+
lines = f.readlines()
|
| 1075 |
+
retdict = {}
|
| 1076 |
+
for line in lines[2:]:
|
| 1077 |
+
colon = line.rfind(':')
|
| 1078 |
+
assert colon > 0, repr(line)
|
| 1079 |
+
name = line[:colon].strip()
|
| 1080 |
+
fields = line[colon + 1 :].strip().split()
|
| 1081 |
+
|
| 1082 |
+
(
|
| 1083 |
+
# in
|
| 1084 |
+
bytes_recv,
|
| 1085 |
+
packets_recv,
|
| 1086 |
+
errin,
|
| 1087 |
+
dropin,
|
| 1088 |
+
_fifoin, # unused
|
| 1089 |
+
_framein, # unused
|
| 1090 |
+
_compressedin, # unused
|
| 1091 |
+
_multicastin, # unused
|
| 1092 |
+
# out
|
| 1093 |
+
bytes_sent,
|
| 1094 |
+
packets_sent,
|
| 1095 |
+
errout,
|
| 1096 |
+
dropout,
|
| 1097 |
+
_fifoout, # unused
|
| 1098 |
+
_collisionsout, # unused
|
| 1099 |
+
_carrierout, # unused
|
| 1100 |
+
_compressedout, # unused
|
| 1101 |
+
) = map(int, fields)
|
| 1102 |
+
|
| 1103 |
+
retdict[name] = (
|
| 1104 |
+
bytes_sent,
|
| 1105 |
+
bytes_recv,
|
| 1106 |
+
packets_sent,
|
| 1107 |
+
packets_recv,
|
| 1108 |
+
errin,
|
| 1109 |
+
errout,
|
| 1110 |
+
dropin,
|
| 1111 |
+
dropout,
|
| 1112 |
+
)
|
| 1113 |
+
return retdict
|
| 1114 |
+
|
| 1115 |
+
|
| 1116 |
+
def net_if_stats():
|
| 1117 |
+
"""Get NIC stats (isup, duplex, speed, mtu)."""
|
| 1118 |
+
duplex_map = {
|
| 1119 |
+
cext.DUPLEX_FULL: NIC_DUPLEX_FULL,
|
| 1120 |
+
cext.DUPLEX_HALF: NIC_DUPLEX_HALF,
|
| 1121 |
+
cext.DUPLEX_UNKNOWN: NIC_DUPLEX_UNKNOWN,
|
| 1122 |
+
}
|
| 1123 |
+
names = net_io_counters().keys()
|
| 1124 |
+
ret = {}
|
| 1125 |
+
for name in names:
|
| 1126 |
+
try:
|
| 1127 |
+
mtu = cext_posix.net_if_mtu(name)
|
| 1128 |
+
flags = cext_posix.net_if_flags(name)
|
| 1129 |
+
duplex, speed = cext.net_if_duplex_speed(name)
|
| 1130 |
+
except OSError as err:
|
| 1131 |
+
# https://github.com/giampaolo/psutil/issues/1279
|
| 1132 |
+
if err.errno != errno.ENODEV:
|
| 1133 |
+
raise
|
| 1134 |
+
else:
|
| 1135 |
+
debug(err)
|
| 1136 |
+
else:
|
| 1137 |
+
output_flags = ','.join(flags)
|
| 1138 |
+
isup = 'running' in flags
|
| 1139 |
+
ret[name] = _common.snicstats(
|
| 1140 |
+
isup, duplex_map[duplex], speed, mtu, output_flags
|
| 1141 |
+
)
|
| 1142 |
+
return ret
|
| 1143 |
+
|
| 1144 |
+
|
| 1145 |
+
# =====================================================================
|
| 1146 |
+
# --- disks
|
| 1147 |
+
# =====================================================================
|
| 1148 |
+
|
| 1149 |
+
|
| 1150 |
+
disk_usage = _psposix.disk_usage
|
| 1151 |
+
|
| 1152 |
+
|
| 1153 |
+
def disk_io_counters(perdisk=False):
|
| 1154 |
+
"""Return disk I/O statistics for every disk installed on the
|
| 1155 |
+
system as a dict of raw tuples.
|
| 1156 |
+
"""
|
| 1157 |
+
|
| 1158 |
+
def read_procfs():
|
| 1159 |
+
# OK, this is a bit confusing. The format of /proc/diskstats can
|
| 1160 |
+
# have 3 variations.
|
| 1161 |
+
# On Linux 2.4 each line has always 15 fields, e.g.:
|
| 1162 |
+
# "3 0 8 hda 8 8 8 8 8 8 8 8 8 8 8"
|
| 1163 |
+
# On Linux 2.6+ each line *usually* has 14 fields, and the disk
|
| 1164 |
+
# name is in another position, like this:
|
| 1165 |
+
# "3 0 hda 8 8 8 8 8 8 8 8 8 8 8"
|
| 1166 |
+
# ...unless (Linux 2.6) the line refers to a partition instead
|
| 1167 |
+
# of a disk, in which case the line has less fields (7):
|
| 1168 |
+
# "3 1 hda1 8 8 8 8"
|
| 1169 |
+
# 4.18+ has 4 fields added:
|
| 1170 |
+
# "3 0 hda 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0"
|
| 1171 |
+
# 5.5 has 2 more fields.
|
| 1172 |
+
# See:
|
| 1173 |
+
# https://www.kernel.org/doc/Documentation/iostats.txt
|
| 1174 |
+
# https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
|
| 1175 |
+
with open_text("%s/diskstats" % get_procfs_path()) as f:
|
| 1176 |
+
lines = f.readlines()
|
| 1177 |
+
for line in lines:
|
| 1178 |
+
fields = line.split()
|
| 1179 |
+
flen = len(fields)
|
| 1180 |
+
# fmt: off
|
| 1181 |
+
if flen == 15:
|
| 1182 |
+
# Linux 2.4
|
| 1183 |
+
name = fields[3]
|
| 1184 |
+
reads = int(fields[2])
|
| 1185 |
+
(reads_merged, rbytes, rtime, writes, writes_merged,
|
| 1186 |
+
wbytes, wtime, _, busy_time, _) = map(int, fields[4:14])
|
| 1187 |
+
elif flen == 14 or flen >= 18:
|
| 1188 |
+
# Linux 2.6+, line referring to a disk
|
| 1189 |
+
name = fields[2]
|
| 1190 |
+
(reads, reads_merged, rbytes, rtime, writes, writes_merged,
|
| 1191 |
+
wbytes, wtime, _, busy_time, _) = map(int, fields[3:14])
|
| 1192 |
+
elif flen == 7:
|
| 1193 |
+
# Linux 2.6+, line referring to a partition
|
| 1194 |
+
name = fields[2]
|
| 1195 |
+
reads, rbytes, writes, wbytes = map(int, fields[3:])
|
| 1196 |
+
rtime = wtime = reads_merged = writes_merged = busy_time = 0
|
| 1197 |
+
else:
|
| 1198 |
+
raise ValueError("not sure how to interpret line %r" % line)
|
| 1199 |
+
yield (name, reads, writes, rbytes, wbytes, rtime, wtime,
|
| 1200 |
+
reads_merged, writes_merged, busy_time)
|
| 1201 |
+
# fmt: on
|
| 1202 |
+
|
| 1203 |
+
def read_sysfs():
|
| 1204 |
+
for block in os.listdir('/sys/block'):
|
| 1205 |
+
for root, _, files in os.walk(os.path.join('/sys/block', block)):
|
| 1206 |
+
if 'stat' not in files:
|
| 1207 |
+
continue
|
| 1208 |
+
with open_text(os.path.join(root, 'stat')) as f:
|
| 1209 |
+
fields = f.read().strip().split()
|
| 1210 |
+
name = os.path.basename(root)
|
| 1211 |
+
# fmt: off
|
| 1212 |
+
(reads, reads_merged, rbytes, rtime, writes, writes_merged,
|
| 1213 |
+
wbytes, wtime, _, busy_time) = map(int, fields[:10])
|
| 1214 |
+
yield (name, reads, writes, rbytes, wbytes, rtime,
|
| 1215 |
+
wtime, reads_merged, writes_merged, busy_time)
|
| 1216 |
+
# fmt: on
|
| 1217 |
+
|
| 1218 |
+
if os.path.exists('%s/diskstats' % get_procfs_path()):
|
| 1219 |
+
gen = read_procfs()
|
| 1220 |
+
elif os.path.exists('/sys/block'):
|
| 1221 |
+
gen = read_sysfs()
|
| 1222 |
+
else:
|
| 1223 |
+
raise NotImplementedError(
|
| 1224 |
+
"%s/diskstats nor /sys/block filesystem are available on this "
|
| 1225 |
+
"system"
|
| 1226 |
+
% get_procfs_path()
|
| 1227 |
+
)
|
| 1228 |
+
|
| 1229 |
+
retdict = {}
|
| 1230 |
+
for entry in gen:
|
| 1231 |
+
# fmt: off
|
| 1232 |
+
(name, reads, writes, rbytes, wbytes, rtime, wtime, reads_merged,
|
| 1233 |
+
writes_merged, busy_time) = entry
|
| 1234 |
+
if not perdisk and not is_storage_device(name):
|
| 1235 |
+
# perdisk=False means we want to calculate totals so we skip
|
| 1236 |
+
# partitions (e.g. 'sda1', 'nvme0n1p1') and only include
|
| 1237 |
+
# base disk devices (e.g. 'sda', 'nvme0n1'). Base disks
|
| 1238 |
+
# include a total of all their partitions + some extra size
|
| 1239 |
+
# of their own:
|
| 1240 |
+
# $ cat /proc/diskstats
|
| 1241 |
+
# 259 0 sda 10485760 ...
|
| 1242 |
+
# 259 1 sda1 5186039 ...
|
| 1243 |
+
# 259 1 sda2 5082039 ...
|
| 1244 |
+
# See:
|
| 1245 |
+
# https://github.com/giampaolo/psutil/pull/1313
|
| 1246 |
+
continue
|
| 1247 |
+
|
| 1248 |
+
rbytes *= DISK_SECTOR_SIZE
|
| 1249 |
+
wbytes *= DISK_SECTOR_SIZE
|
| 1250 |
+
retdict[name] = (reads, writes, rbytes, wbytes, rtime, wtime,
|
| 1251 |
+
reads_merged, writes_merged, busy_time)
|
| 1252 |
+
# fmt: on
|
| 1253 |
+
|
| 1254 |
+
return retdict
|
| 1255 |
+
|
| 1256 |
+
|
| 1257 |
+
class RootFsDeviceFinder:
|
| 1258 |
+
"""disk_partitions() may return partitions with device == "/dev/root"
|
| 1259 |
+
or "rootfs". This container class uses different strategies to try to
|
| 1260 |
+
obtain the real device path. Resources:
|
| 1261 |
+
https://bootlin.com/blog/find-root-device/
|
| 1262 |
+
https://www.systutorials.com/how-to-find-the-disk-where-root-is-on-in-bash-on-linux/.
|
| 1263 |
+
"""
|
| 1264 |
+
|
| 1265 |
+
__slots__ = ['major', 'minor']
|
| 1266 |
+
|
| 1267 |
+
def __init__(self):
|
| 1268 |
+
dev = os.stat("/").st_dev
|
| 1269 |
+
self.major = os.major(dev)
|
| 1270 |
+
self.minor = os.minor(dev)
|
| 1271 |
+
|
| 1272 |
+
def ask_proc_partitions(self):
|
| 1273 |
+
with open_text("%s/partitions" % get_procfs_path()) as f:
|
| 1274 |
+
for line in f.readlines()[2:]:
|
| 1275 |
+
fields = line.split()
|
| 1276 |
+
if len(fields) < 4: # just for extra safety
|
| 1277 |
+
continue
|
| 1278 |
+
major = int(fields[0]) if fields[0].isdigit() else None
|
| 1279 |
+
minor = int(fields[1]) if fields[1].isdigit() else None
|
| 1280 |
+
name = fields[3]
|
| 1281 |
+
if major == self.major and minor == self.minor:
|
| 1282 |
+
if name: # just for extra safety
|
| 1283 |
+
return "/dev/%s" % name
|
| 1284 |
+
|
| 1285 |
+
def ask_sys_dev_block(self):
|
| 1286 |
+
path = "/sys/dev/block/%s:%s/uevent" % (self.major, self.minor)
|
| 1287 |
+
with open_text(path) as f:
|
| 1288 |
+
for line in f:
|
| 1289 |
+
if line.startswith("DEVNAME="):
|
| 1290 |
+
name = line.strip().rpartition("DEVNAME=")[2]
|
| 1291 |
+
if name: # just for extra safety
|
| 1292 |
+
return "/dev/%s" % name
|
| 1293 |
+
|
| 1294 |
+
def ask_sys_class_block(self):
|
| 1295 |
+
needle = "%s:%s" % (self.major, self.minor)
|
| 1296 |
+
files = glob.iglob("/sys/class/block/*/dev")
|
| 1297 |
+
for file in files:
|
| 1298 |
+
try:
|
| 1299 |
+
f = open_text(file)
|
| 1300 |
+
except FileNotFoundError: # race condition
|
| 1301 |
+
continue
|
| 1302 |
+
else:
|
| 1303 |
+
with f:
|
| 1304 |
+
data = f.read().strip()
|
| 1305 |
+
if data == needle:
|
| 1306 |
+
name = os.path.basename(os.path.dirname(file))
|
| 1307 |
+
return "/dev/%s" % name
|
| 1308 |
+
|
| 1309 |
+
def find(self):
|
| 1310 |
+
path = None
|
| 1311 |
+
if path is None:
|
| 1312 |
+
try:
|
| 1313 |
+
path = self.ask_proc_partitions()
|
| 1314 |
+
except (IOError, OSError) as err:
|
| 1315 |
+
debug(err)
|
| 1316 |
+
if path is None:
|
| 1317 |
+
try:
|
| 1318 |
+
path = self.ask_sys_dev_block()
|
| 1319 |
+
except (IOError, OSError) as err:
|
| 1320 |
+
debug(err)
|
| 1321 |
+
if path is None:
|
| 1322 |
+
try:
|
| 1323 |
+
path = self.ask_sys_class_block()
|
| 1324 |
+
except (IOError, OSError) as err:
|
| 1325 |
+
debug(err)
|
| 1326 |
+
# We use exists() because the "/dev/*" part of the path is hard
|
| 1327 |
+
# coded, so we want to be sure.
|
| 1328 |
+
if path is not None and os.path.exists(path):
|
| 1329 |
+
return path
|
| 1330 |
+
|
| 1331 |
+
|
| 1332 |
+
def disk_partitions(all=False):
|
| 1333 |
+
"""Return mounted disk partitions as a list of namedtuples."""
|
| 1334 |
+
fstypes = set()
|
| 1335 |
+
procfs_path = get_procfs_path()
|
| 1336 |
+
if not all:
|
| 1337 |
+
with open_text("%s/filesystems" % procfs_path) as f:
|
| 1338 |
+
for line in f:
|
| 1339 |
+
line = line.strip()
|
| 1340 |
+
if not line.startswith("nodev"):
|
| 1341 |
+
fstypes.add(line.strip())
|
| 1342 |
+
else:
|
| 1343 |
+
# ignore all lines starting with "nodev" except "nodev zfs"
|
| 1344 |
+
fstype = line.split("\t")[1]
|
| 1345 |
+
if fstype == "zfs":
|
| 1346 |
+
fstypes.add("zfs")
|
| 1347 |
+
|
| 1348 |
+
# See: https://github.com/giampaolo/psutil/issues/1307
|
| 1349 |
+
if procfs_path == "/proc" and os.path.isfile('/etc/mtab'):
|
| 1350 |
+
mounts_path = os.path.realpath("/etc/mtab")
|
| 1351 |
+
else:
|
| 1352 |
+
mounts_path = os.path.realpath("%s/self/mounts" % procfs_path)
|
| 1353 |
+
|
| 1354 |
+
retlist = []
|
| 1355 |
+
partitions = cext.disk_partitions(mounts_path)
|
| 1356 |
+
for partition in partitions:
|
| 1357 |
+
device, mountpoint, fstype, opts = partition
|
| 1358 |
+
if device == 'none':
|
| 1359 |
+
device = ''
|
| 1360 |
+
if device in {"/dev/root", "rootfs"}:
|
| 1361 |
+
device = RootFsDeviceFinder().find() or device
|
| 1362 |
+
if not all:
|
| 1363 |
+
if not device or fstype not in fstypes:
|
| 1364 |
+
continue
|
| 1365 |
+
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
|
| 1366 |
+
retlist.append(ntuple)
|
| 1367 |
+
|
| 1368 |
+
return retlist
|
| 1369 |
+
|
| 1370 |
+
|
| 1371 |
+
# =====================================================================
|
| 1372 |
+
# --- sensors
|
| 1373 |
+
# =====================================================================
|
| 1374 |
+
|
| 1375 |
+
|
| 1376 |
+
def sensors_temperatures():
|
| 1377 |
+
"""Return hardware (CPU and others) temperatures as a dict
|
| 1378 |
+
including hardware name, label, current, max and critical
|
| 1379 |
+
temperatures.
|
| 1380 |
+
|
| 1381 |
+
Implementation notes:
|
| 1382 |
+
- /sys/class/hwmon looks like the most recent interface to
|
| 1383 |
+
retrieve this info, and this implementation relies on it
|
| 1384 |
+
only (old distros will probably use something else)
|
| 1385 |
+
- lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
|
| 1386 |
+
- /sys/class/thermal/thermal_zone* is another one but it's more
|
| 1387 |
+
difficult to parse
|
| 1388 |
+
"""
|
| 1389 |
+
ret = collections.defaultdict(list)
|
| 1390 |
+
basenames = glob.glob('/sys/class/hwmon/hwmon*/temp*_*')
|
| 1391 |
+
# CentOS has an intermediate /device directory:
|
| 1392 |
+
# https://github.com/giampaolo/psutil/issues/971
|
| 1393 |
+
# https://github.com/nicolargo/glances/issues/1060
|
| 1394 |
+
basenames.extend(glob.glob('/sys/class/hwmon/hwmon*/device/temp*_*'))
|
| 1395 |
+
basenames = sorted(set([x.split('_')[0] for x in basenames]))
|
| 1396 |
+
|
| 1397 |
+
# Only add the coretemp hwmon entries if they're not already in
|
| 1398 |
+
# /sys/class/hwmon/
|
| 1399 |
+
# https://github.com/giampaolo/psutil/issues/1708
|
| 1400 |
+
# https://github.com/giampaolo/psutil/pull/1648
|
| 1401 |
+
basenames2 = glob.glob(
|
| 1402 |
+
'/sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_*'
|
| 1403 |
+
)
|
| 1404 |
+
repl = re.compile('/sys/devices/platform/coretemp.*/hwmon/')
|
| 1405 |
+
for name in basenames2:
|
| 1406 |
+
altname = repl.sub('/sys/class/hwmon/', name)
|
| 1407 |
+
if altname not in basenames:
|
| 1408 |
+
basenames.append(name)
|
| 1409 |
+
|
| 1410 |
+
for base in basenames:
|
| 1411 |
+
try:
|
| 1412 |
+
path = base + '_input'
|
| 1413 |
+
current = float(bcat(path)) / 1000.0
|
| 1414 |
+
path = os.path.join(os.path.dirname(base), 'name')
|
| 1415 |
+
unit_name = cat(path).strip()
|
| 1416 |
+
except (IOError, OSError, ValueError):
|
| 1417 |
+
# A lot of things can go wrong here, so let's just skip the
|
| 1418 |
+
# whole entry. Sure thing is Linux's /sys/class/hwmon really
|
| 1419 |
+
# is a stinky broken mess.
|
| 1420 |
+
# https://github.com/giampaolo/psutil/issues/1009
|
| 1421 |
+
# https://github.com/giampaolo/psutil/issues/1101
|
| 1422 |
+
# https://github.com/giampaolo/psutil/issues/1129
|
| 1423 |
+
# https://github.com/giampaolo/psutil/issues/1245
|
| 1424 |
+
# https://github.com/giampaolo/psutil/issues/1323
|
| 1425 |
+
continue
|
| 1426 |
+
|
| 1427 |
+
high = bcat(base + '_max', fallback=None)
|
| 1428 |
+
critical = bcat(base + '_crit', fallback=None)
|
| 1429 |
+
label = cat(base + '_label', fallback='').strip()
|
| 1430 |
+
|
| 1431 |
+
if high is not None:
|
| 1432 |
+
try:
|
| 1433 |
+
high = float(high) / 1000.0
|
| 1434 |
+
except ValueError:
|
| 1435 |
+
high = None
|
| 1436 |
+
if critical is not None:
|
| 1437 |
+
try:
|
| 1438 |
+
critical = float(critical) / 1000.0
|
| 1439 |
+
except ValueError:
|
| 1440 |
+
critical = None
|
| 1441 |
+
|
| 1442 |
+
ret[unit_name].append((label, current, high, critical))
|
| 1443 |
+
|
| 1444 |
+
# Indication that no sensors were detected in /sys/class/hwmon/
|
| 1445 |
+
if not basenames:
|
| 1446 |
+
basenames = glob.glob('/sys/class/thermal/thermal_zone*')
|
| 1447 |
+
basenames = sorted(set(basenames))
|
| 1448 |
+
|
| 1449 |
+
for base in basenames:
|
| 1450 |
+
try:
|
| 1451 |
+
path = os.path.join(base, 'temp')
|
| 1452 |
+
current = float(bcat(path)) / 1000.0
|
| 1453 |
+
path = os.path.join(base, 'type')
|
| 1454 |
+
unit_name = cat(path).strip()
|
| 1455 |
+
except (IOError, OSError, ValueError) as err:
|
| 1456 |
+
debug(err)
|
| 1457 |
+
continue
|
| 1458 |
+
|
| 1459 |
+
trip_paths = glob.glob(base + '/trip_point*')
|
| 1460 |
+
trip_points = set([
|
| 1461 |
+
'_'.join(os.path.basename(p).split('_')[0:3])
|
| 1462 |
+
for p in trip_paths
|
| 1463 |
+
])
|
| 1464 |
+
critical = None
|
| 1465 |
+
high = None
|
| 1466 |
+
for trip_point in trip_points:
|
| 1467 |
+
path = os.path.join(base, trip_point + "_type")
|
| 1468 |
+
trip_type = cat(path, fallback='').strip()
|
| 1469 |
+
if trip_type == 'critical':
|
| 1470 |
+
critical = bcat(
|
| 1471 |
+
os.path.join(base, trip_point + "_temp"), fallback=None
|
| 1472 |
+
)
|
| 1473 |
+
elif trip_type == 'high':
|
| 1474 |
+
high = bcat(
|
| 1475 |
+
os.path.join(base, trip_point + "_temp"), fallback=None
|
| 1476 |
+
)
|
| 1477 |
+
|
| 1478 |
+
if high is not None:
|
| 1479 |
+
try:
|
| 1480 |
+
high = float(high) / 1000.0
|
| 1481 |
+
except ValueError:
|
| 1482 |
+
high = None
|
| 1483 |
+
if critical is not None:
|
| 1484 |
+
try:
|
| 1485 |
+
critical = float(critical) / 1000.0
|
| 1486 |
+
except ValueError:
|
| 1487 |
+
critical = None
|
| 1488 |
+
|
| 1489 |
+
ret[unit_name].append(('', current, high, critical))
|
| 1490 |
+
|
| 1491 |
+
return dict(ret)
|
| 1492 |
+
|
| 1493 |
+
|
| 1494 |
+
def sensors_fans():
|
| 1495 |
+
"""Return hardware fans info (for CPU and other peripherals) as a
|
| 1496 |
+
dict including hardware label and current speed.
|
| 1497 |
+
|
| 1498 |
+
Implementation notes:
|
| 1499 |
+
- /sys/class/hwmon looks like the most recent interface to
|
| 1500 |
+
retrieve this info, and this implementation relies on it
|
| 1501 |
+
only (old distros will probably use something else)
|
| 1502 |
+
- lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
|
| 1503 |
+
"""
|
| 1504 |
+
ret = collections.defaultdict(list)
|
| 1505 |
+
basenames = glob.glob('/sys/class/hwmon/hwmon*/fan*_*')
|
| 1506 |
+
if not basenames:
|
| 1507 |
+
# CentOS has an intermediate /device directory:
|
| 1508 |
+
# https://github.com/giampaolo/psutil/issues/971
|
| 1509 |
+
basenames = glob.glob('/sys/class/hwmon/hwmon*/device/fan*_*')
|
| 1510 |
+
|
| 1511 |
+
basenames = sorted(set([x.split('_')[0] for x in basenames]))
|
| 1512 |
+
for base in basenames:
|
| 1513 |
+
try:
|
| 1514 |
+
current = int(bcat(base + '_input'))
|
| 1515 |
+
except (IOError, OSError) as err:
|
| 1516 |
+
debug(err)
|
| 1517 |
+
continue
|
| 1518 |
+
unit_name = cat(os.path.join(os.path.dirname(base), 'name')).strip()
|
| 1519 |
+
label = cat(base + '_label', fallback='').strip()
|
| 1520 |
+
ret[unit_name].append(_common.sfan(label, current))
|
| 1521 |
+
|
| 1522 |
+
return dict(ret)
|
| 1523 |
+
|
| 1524 |
+
|
| 1525 |
+
def sensors_battery():
|
| 1526 |
+
"""Return battery information.
|
| 1527 |
+
Implementation note: it appears /sys/class/power_supply/BAT0/
|
| 1528 |
+
directory structure may vary and provide files with the same
|
| 1529 |
+
meaning but under different names, see:
|
| 1530 |
+
https://github.com/giampaolo/psutil/issues/966.
|
| 1531 |
+
"""
|
| 1532 |
+
null = object()
|
| 1533 |
+
|
| 1534 |
+
def multi_bcat(*paths):
|
| 1535 |
+
"""Attempt to read the content of multiple files which may
|
| 1536 |
+
not exist. If none of them exist return None.
|
| 1537 |
+
"""
|
| 1538 |
+
for path in paths:
|
| 1539 |
+
ret = bcat(path, fallback=null)
|
| 1540 |
+
if ret != null:
|
| 1541 |
+
try:
|
| 1542 |
+
return int(ret)
|
| 1543 |
+
except ValueError:
|
| 1544 |
+
return ret.strip()
|
| 1545 |
+
return None
|
| 1546 |
+
|
| 1547 |
+
bats = [
|
| 1548 |
+
x
|
| 1549 |
+
for x in os.listdir(POWER_SUPPLY_PATH)
|
| 1550 |
+
if x.startswith('BAT') or 'battery' in x.lower()
|
| 1551 |
+
]
|
| 1552 |
+
if not bats:
|
| 1553 |
+
return None
|
| 1554 |
+
# Get the first available battery. Usually this is "BAT0", except
|
| 1555 |
+
# some rare exceptions:
|
| 1556 |
+
# https://github.com/giampaolo/psutil/issues/1238
|
| 1557 |
+
root = os.path.join(POWER_SUPPLY_PATH, sorted(bats)[0])
|
| 1558 |
+
|
| 1559 |
+
# Base metrics.
|
| 1560 |
+
energy_now = multi_bcat(root + "/energy_now", root + "/charge_now")
|
| 1561 |
+
power_now = multi_bcat(root + "/power_now", root + "/current_now")
|
| 1562 |
+
energy_full = multi_bcat(root + "/energy_full", root + "/charge_full")
|
| 1563 |
+
time_to_empty = multi_bcat(root + "/time_to_empty_now")
|
| 1564 |
+
|
| 1565 |
+
# Percent. If we have energy_full the percentage will be more
|
| 1566 |
+
# accurate compared to reading /capacity file (float vs. int).
|
| 1567 |
+
if energy_full is not None and energy_now is not None:
|
| 1568 |
+
try:
|
| 1569 |
+
percent = 100.0 * energy_now / energy_full
|
| 1570 |
+
except ZeroDivisionError:
|
| 1571 |
+
percent = 0.0
|
| 1572 |
+
else:
|
| 1573 |
+
percent = int(cat(root + "/capacity", fallback=-1))
|
| 1574 |
+
if percent == -1:
|
| 1575 |
+
return None
|
| 1576 |
+
|
| 1577 |
+
# Is AC power cable plugged in?
|
| 1578 |
+
# Note: AC0 is not always available and sometimes (e.g. CentOS7)
|
| 1579 |
+
# it's called "AC".
|
| 1580 |
+
power_plugged = None
|
| 1581 |
+
online = multi_bcat(
|
| 1582 |
+
os.path.join(POWER_SUPPLY_PATH, "AC0/online"),
|
| 1583 |
+
os.path.join(POWER_SUPPLY_PATH, "AC/online"),
|
| 1584 |
+
)
|
| 1585 |
+
if online is not None:
|
| 1586 |
+
power_plugged = online == 1
|
| 1587 |
+
else:
|
| 1588 |
+
status = cat(root + "/status", fallback="").strip().lower()
|
| 1589 |
+
if status == "discharging":
|
| 1590 |
+
power_plugged = False
|
| 1591 |
+
elif status in {"charging", "full"}:
|
| 1592 |
+
power_plugged = True
|
| 1593 |
+
|
| 1594 |
+
# Seconds left.
|
| 1595 |
+
# Note to self: we may also calculate the charging ETA as per:
|
| 1596 |
+
# https://github.com/thialfihar/dotfiles/blob/
|
| 1597 |
+
# 013937745fd9050c30146290e8f963d65c0179e6/bin/battery.py#L55
|
| 1598 |
+
if power_plugged:
|
| 1599 |
+
secsleft = _common.POWER_TIME_UNLIMITED
|
| 1600 |
+
elif energy_now is not None and power_now is not None:
|
| 1601 |
+
try:
|
| 1602 |
+
secsleft = int(energy_now / power_now * 3600)
|
| 1603 |
+
except ZeroDivisionError:
|
| 1604 |
+
secsleft = _common.POWER_TIME_UNKNOWN
|
| 1605 |
+
elif time_to_empty is not None:
|
| 1606 |
+
secsleft = int(time_to_empty * 60)
|
| 1607 |
+
if secsleft < 0:
|
| 1608 |
+
secsleft = _common.POWER_TIME_UNKNOWN
|
| 1609 |
+
else:
|
| 1610 |
+
secsleft = _common.POWER_TIME_UNKNOWN
|
| 1611 |
+
|
| 1612 |
+
return _common.sbattery(percent, secsleft, power_plugged)
|
| 1613 |
+
|
| 1614 |
+
|
| 1615 |
+
# =====================================================================
|
| 1616 |
+
# --- other system functions
|
| 1617 |
+
# =====================================================================
|
| 1618 |
+
|
| 1619 |
+
|
| 1620 |
+
def users():
|
| 1621 |
+
"""Return currently connected users as a list of namedtuples."""
|
| 1622 |
+
retlist = []
|
| 1623 |
+
rawlist = cext.users()
|
| 1624 |
+
for item in rawlist:
|
| 1625 |
+
user, tty, hostname, tstamp, pid = item
|
| 1626 |
+
nt = _common.suser(user, tty or None, hostname, tstamp, pid)
|
| 1627 |
+
retlist.append(nt)
|
| 1628 |
+
return retlist
|
| 1629 |
+
|
| 1630 |
+
|
| 1631 |
+
def boot_time():
|
| 1632 |
+
"""Return the system boot time expressed in seconds since the epoch."""
|
| 1633 |
+
global BOOT_TIME
|
| 1634 |
+
path = '%s/stat' % get_procfs_path()
|
| 1635 |
+
with open_binary(path) as f:
|
| 1636 |
+
for line in f:
|
| 1637 |
+
if line.startswith(b'btime'):
|
| 1638 |
+
ret = float(line.strip().split()[1])
|
| 1639 |
+
BOOT_TIME = ret
|
| 1640 |
+
return ret
|
| 1641 |
+
raise RuntimeError("line 'btime' not found in %s" % path)
|
| 1642 |
+
|
| 1643 |
+
|
| 1644 |
+
# =====================================================================
|
| 1645 |
+
# --- processes
|
| 1646 |
+
# =====================================================================
|
| 1647 |
+
|
| 1648 |
+
|
| 1649 |
+
def pids():
|
| 1650 |
+
"""Returns a list of PIDs currently running on the system."""
|
| 1651 |
+
return [int(x) for x in os.listdir(b(get_procfs_path())) if x.isdigit()]
|
| 1652 |
+
|
| 1653 |
+
|
| 1654 |
+
def pid_exists(pid):
|
| 1655 |
+
"""Check for the existence of a unix PID. Linux TIDs are not
|
| 1656 |
+
supported (always return False).
|
| 1657 |
+
"""
|
| 1658 |
+
if not _psposix.pid_exists(pid):
|
| 1659 |
+
return False
|
| 1660 |
+
else:
|
| 1661 |
+
# Linux's apparently does not distinguish between PIDs and TIDs
|
| 1662 |
+
# (thread IDs).
|
| 1663 |
+
# listdir("/proc") won't show any TID (only PIDs) but
|
| 1664 |
+
# os.stat("/proc/{tid}") will succeed if {tid} exists.
|
| 1665 |
+
# os.kill() can also be passed a TID. This is quite confusing.
|
| 1666 |
+
# In here we want to enforce this distinction and support PIDs
|
| 1667 |
+
# only, see:
|
| 1668 |
+
# https://github.com/giampaolo/psutil/issues/687
|
| 1669 |
+
try:
|
| 1670 |
+
# Note: already checked that this is faster than using a
|
| 1671 |
+
# regular expr. Also (a lot) faster than doing
|
| 1672 |
+
# 'return pid in pids()'
|
| 1673 |
+
path = "%s/%s/status" % (get_procfs_path(), pid)
|
| 1674 |
+
with open_binary(path) as f:
|
| 1675 |
+
for line in f:
|
| 1676 |
+
if line.startswith(b"Tgid:"):
|
| 1677 |
+
tgid = int(line.split()[1])
|
| 1678 |
+
# If tgid and pid are the same then we're
|
| 1679 |
+
# dealing with a process PID.
|
| 1680 |
+
return tgid == pid
|
| 1681 |
+
raise ValueError("'Tgid' line not found in %s" % path)
|
| 1682 |
+
except (EnvironmentError, ValueError):
|
| 1683 |
+
return pid in pids()
|
| 1684 |
+
|
| 1685 |
+
|
| 1686 |
+
def ppid_map():
|
| 1687 |
+
"""Obtain a {pid: ppid, ...} dict for all running processes in
|
| 1688 |
+
one shot. Used to speed up Process.children().
|
| 1689 |
+
"""
|
| 1690 |
+
ret = {}
|
| 1691 |
+
procfs_path = get_procfs_path()
|
| 1692 |
+
for pid in pids():
|
| 1693 |
+
try:
|
| 1694 |
+
with open_binary("%s/%s/stat" % (procfs_path, pid)) as f:
|
| 1695 |
+
data = f.read()
|
| 1696 |
+
except (FileNotFoundError, ProcessLookupError):
|
| 1697 |
+
# Note: we should be able to access /stat for all processes
|
| 1698 |
+
# aka it's unlikely we'll bump into EPERM, which is good.
|
| 1699 |
+
pass
|
| 1700 |
+
else:
|
| 1701 |
+
rpar = data.rfind(b')')
|
| 1702 |
+
dset = data[rpar + 2 :].split()
|
| 1703 |
+
ppid = int(dset[1])
|
| 1704 |
+
ret[pid] = ppid
|
| 1705 |
+
return ret
|
| 1706 |
+
|
| 1707 |
+
|
| 1708 |
+
def wrap_exceptions(fun):
|
| 1709 |
+
"""Decorator which translates bare OSError and IOError exceptions
|
| 1710 |
+
into NoSuchProcess and AccessDenied.
|
| 1711 |
+
"""
|
| 1712 |
+
|
| 1713 |
+
@functools.wraps(fun)
|
| 1714 |
+
def wrapper(self, *args, **kwargs):
|
| 1715 |
+
try:
|
| 1716 |
+
return fun(self, *args, **kwargs)
|
| 1717 |
+
except PermissionError:
|
| 1718 |
+
raise AccessDenied(self.pid, self._name)
|
| 1719 |
+
except ProcessLookupError:
|
| 1720 |
+
self._raise_if_zombie()
|
| 1721 |
+
raise NoSuchProcess(self.pid, self._name)
|
| 1722 |
+
except FileNotFoundError:
|
| 1723 |
+
self._raise_if_zombie()
|
| 1724 |
+
# /proc/PID directory may still exist, but the files within
|
| 1725 |
+
# it may not, indicating the process is gone, see:
|
| 1726 |
+
# https://github.com/giampaolo/psutil/issues/2418
|
| 1727 |
+
if not os.path.exists(
|
| 1728 |
+
"%s/%s/stat" % (self._procfs_path, self.pid)
|
| 1729 |
+
):
|
| 1730 |
+
raise NoSuchProcess(self.pid, self._name)
|
| 1731 |
+
raise
|
| 1732 |
+
|
| 1733 |
+
return wrapper
|
| 1734 |
+
|
| 1735 |
+
|
| 1736 |
+
class Process:
|
| 1737 |
+
"""Linux process implementation."""
|
| 1738 |
+
|
| 1739 |
+
__slots__ = ["_cache", "_name", "_ppid", "_procfs_path", "pid"]
|
| 1740 |
+
|
| 1741 |
+
def __init__(self, pid):
|
| 1742 |
+
self.pid = pid
|
| 1743 |
+
self._name = None
|
| 1744 |
+
self._ppid = None
|
| 1745 |
+
self._procfs_path = get_procfs_path()
|
| 1746 |
+
|
| 1747 |
+
def _is_zombie(self):
|
| 1748 |
+
# Note: most of the times Linux is able to return info about the
|
| 1749 |
+
# process even if it's a zombie, and /proc/{pid} will exist.
|
| 1750 |
+
# There are some exceptions though, like exe(), cmdline() and
|
| 1751 |
+
# memory_maps(). In these cases /proc/{pid}/{file} exists but
|
| 1752 |
+
# it's empty. Instead of returning a "null" value we'll raise an
|
| 1753 |
+
# exception.
|
| 1754 |
+
try:
|
| 1755 |
+
data = bcat("%s/%s/stat" % (self._procfs_path, self.pid))
|
| 1756 |
+
except (IOError, OSError):
|
| 1757 |
+
return False
|
| 1758 |
+
else:
|
| 1759 |
+
rpar = data.rfind(b')')
|
| 1760 |
+
status = data[rpar + 2 : rpar + 3]
|
| 1761 |
+
return status == b"Z"
|
| 1762 |
+
|
| 1763 |
+
def _raise_if_zombie(self):
|
| 1764 |
+
if self._is_zombie():
|
| 1765 |
+
raise ZombieProcess(self.pid, self._name, self._ppid)
|
| 1766 |
+
|
| 1767 |
+
def _raise_if_not_alive(self):
|
| 1768 |
+
"""Raise NSP if the process disappeared on us."""
|
| 1769 |
+
# For those C function who do not raise NSP, possibly returning
|
| 1770 |
+
# incorrect or incomplete result.
|
| 1771 |
+
os.stat('%s/%s' % (self._procfs_path, self.pid))
|
| 1772 |
+
|
| 1773 |
+
@wrap_exceptions
|
| 1774 |
+
@memoize_when_activated
|
| 1775 |
+
def _parse_stat_file(self):
|
| 1776 |
+
"""Parse /proc/{pid}/stat file and return a dict with various
|
| 1777 |
+
process info.
|
| 1778 |
+
Using "man proc" as a reference: where "man proc" refers to
|
| 1779 |
+
position N always subtract 3 (e.g ppid position 4 in
|
| 1780 |
+
'man proc' == position 1 in here).
|
| 1781 |
+
The return value is cached in case oneshot() ctx manager is
|
| 1782 |
+
in use.
|
| 1783 |
+
"""
|
| 1784 |
+
data = bcat("%s/%s/stat" % (self._procfs_path, self.pid))
|
| 1785 |
+
# Process name is between parentheses. It can contain spaces and
|
| 1786 |
+
# other parentheses. This is taken into account by looking for
|
| 1787 |
+
# the first occurrence of "(" and the last occurrence of ")".
|
| 1788 |
+
rpar = data.rfind(b')')
|
| 1789 |
+
name = data[data.find(b'(') + 1 : rpar]
|
| 1790 |
+
fields = data[rpar + 2 :].split()
|
| 1791 |
+
|
| 1792 |
+
ret = {}
|
| 1793 |
+
ret['name'] = name
|
| 1794 |
+
ret['status'] = fields[0]
|
| 1795 |
+
ret['ppid'] = fields[1]
|
| 1796 |
+
ret['ttynr'] = fields[4]
|
| 1797 |
+
ret['utime'] = fields[11]
|
| 1798 |
+
ret['stime'] = fields[12]
|
| 1799 |
+
ret['children_utime'] = fields[13]
|
| 1800 |
+
ret['children_stime'] = fields[14]
|
| 1801 |
+
ret['create_time'] = fields[19]
|
| 1802 |
+
ret['cpu_num'] = fields[36]
|
| 1803 |
+
try:
|
| 1804 |
+
ret['blkio_ticks'] = fields[39] # aka 'delayacct_blkio_ticks'
|
| 1805 |
+
except IndexError:
|
| 1806 |
+
# https://github.com/giampaolo/psutil/issues/2455
|
| 1807 |
+
debug("can't get blkio_ticks, set iowait to 0")
|
| 1808 |
+
ret['blkio_ticks'] = 0
|
| 1809 |
+
|
| 1810 |
+
return ret
|
| 1811 |
+
|
| 1812 |
+
@wrap_exceptions
|
| 1813 |
+
@memoize_when_activated
|
| 1814 |
+
def _read_status_file(self):
|
| 1815 |
+
"""Read /proc/{pid}/stat file and return its content.
|
| 1816 |
+
The return value is cached in case oneshot() ctx manager is
|
| 1817 |
+
in use.
|
| 1818 |
+
"""
|
| 1819 |
+
with open_binary("%s/%s/status" % (self._procfs_path, self.pid)) as f:
|
| 1820 |
+
return f.read()
|
| 1821 |
+
|
| 1822 |
+
@wrap_exceptions
|
| 1823 |
+
@memoize_when_activated
|
| 1824 |
+
def _read_smaps_file(self):
|
| 1825 |
+
with open_binary("%s/%s/smaps" % (self._procfs_path, self.pid)) as f:
|
| 1826 |
+
return f.read().strip()
|
| 1827 |
+
|
| 1828 |
+
def oneshot_enter(self):
|
| 1829 |
+
self._parse_stat_file.cache_activate(self)
|
| 1830 |
+
self._read_status_file.cache_activate(self)
|
| 1831 |
+
self._read_smaps_file.cache_activate(self)
|
| 1832 |
+
|
| 1833 |
+
def oneshot_exit(self):
|
| 1834 |
+
self._parse_stat_file.cache_deactivate(self)
|
| 1835 |
+
self._read_status_file.cache_deactivate(self)
|
| 1836 |
+
self._read_smaps_file.cache_deactivate(self)
|
| 1837 |
+
|
| 1838 |
+
@wrap_exceptions
|
| 1839 |
+
def name(self):
|
| 1840 |
+
name = self._parse_stat_file()['name']
|
| 1841 |
+
if PY3:
|
| 1842 |
+
name = decode(name)
|
| 1843 |
+
# XXX - gets changed later and probably needs refactoring
|
| 1844 |
+
return name
|
| 1845 |
+
|
| 1846 |
+
@wrap_exceptions
|
| 1847 |
+
def exe(self):
|
| 1848 |
+
try:
|
| 1849 |
+
return readlink("%s/%s/exe" % (self._procfs_path, self.pid))
|
| 1850 |
+
except (FileNotFoundError, ProcessLookupError):
|
| 1851 |
+
self._raise_if_zombie()
|
| 1852 |
+
# no such file error; might be raised also if the
|
| 1853 |
+
# path actually exists for system processes with
|
| 1854 |
+
# low pids (about 0-20)
|
| 1855 |
+
if os.path.lexists("%s/%s" % (self._procfs_path, self.pid)):
|
| 1856 |
+
return ""
|
| 1857 |
+
raise
|
| 1858 |
+
|
| 1859 |
+
@wrap_exceptions
|
| 1860 |
+
def cmdline(self):
|
| 1861 |
+
with open_text("%s/%s/cmdline" % (self._procfs_path, self.pid)) as f:
|
| 1862 |
+
data = f.read()
|
| 1863 |
+
if not data:
|
| 1864 |
+
# may happen in case of zombie process
|
| 1865 |
+
self._raise_if_zombie()
|
| 1866 |
+
return []
|
| 1867 |
+
# 'man proc' states that args are separated by null bytes '\0'
|
| 1868 |
+
# and last char is supposed to be a null byte. Nevertheless
|
| 1869 |
+
# some processes may change their cmdline after being started
|
| 1870 |
+
# (via setproctitle() or similar), they are usually not
|
| 1871 |
+
# compliant with this rule and use spaces instead. Google
|
| 1872 |
+
# Chrome process is an example. See:
|
| 1873 |
+
# https://github.com/giampaolo/psutil/issues/1179
|
| 1874 |
+
sep = '\x00' if data.endswith('\x00') else ' '
|
| 1875 |
+
if data.endswith(sep):
|
| 1876 |
+
data = data[:-1]
|
| 1877 |
+
cmdline = data.split(sep)
|
| 1878 |
+
# Sometimes last char is a null byte '\0' but the args are
|
| 1879 |
+
# separated by spaces, see: https://github.com/giampaolo/psutil/
|
| 1880 |
+
# issues/1179#issuecomment-552984549
|
| 1881 |
+
if sep == '\x00' and len(cmdline) == 1 and ' ' in data:
|
| 1882 |
+
cmdline = data.split(' ')
|
| 1883 |
+
return cmdline
|
| 1884 |
+
|
| 1885 |
+
@wrap_exceptions
|
| 1886 |
+
def environ(self):
|
| 1887 |
+
with open_text("%s/%s/environ" % (self._procfs_path, self.pid)) as f:
|
| 1888 |
+
data = f.read()
|
| 1889 |
+
return parse_environ_block(data)
|
| 1890 |
+
|
| 1891 |
+
@wrap_exceptions
|
| 1892 |
+
def terminal(self):
|
| 1893 |
+
tty_nr = int(self._parse_stat_file()['ttynr'])
|
| 1894 |
+
tmap = _psposix.get_terminal_map()
|
| 1895 |
+
try:
|
| 1896 |
+
return tmap[tty_nr]
|
| 1897 |
+
except KeyError:
|
| 1898 |
+
return None
|
| 1899 |
+
|
| 1900 |
+
# May not be available on old kernels.
|
| 1901 |
+
if os.path.exists('/proc/%s/io' % os.getpid()):
|
| 1902 |
+
|
| 1903 |
+
@wrap_exceptions
|
| 1904 |
+
def io_counters(self):
|
| 1905 |
+
fname = "%s/%s/io" % (self._procfs_path, self.pid)
|
| 1906 |
+
fields = {}
|
| 1907 |
+
with open_binary(fname) as f:
|
| 1908 |
+
for line in f:
|
| 1909 |
+
# https://github.com/giampaolo/psutil/issues/1004
|
| 1910 |
+
line = line.strip()
|
| 1911 |
+
if line:
|
| 1912 |
+
try:
|
| 1913 |
+
name, value = line.split(b': ')
|
| 1914 |
+
except ValueError:
|
| 1915 |
+
# https://github.com/giampaolo/psutil/issues/1004
|
| 1916 |
+
continue
|
| 1917 |
+
else:
|
| 1918 |
+
fields[name] = int(value)
|
| 1919 |
+
if not fields:
|
| 1920 |
+
raise RuntimeError("%s file was empty" % fname)
|
| 1921 |
+
try:
|
| 1922 |
+
return pio(
|
| 1923 |
+
fields[b'syscr'], # read syscalls
|
| 1924 |
+
fields[b'syscw'], # write syscalls
|
| 1925 |
+
fields[b'read_bytes'], # read bytes
|
| 1926 |
+
fields[b'write_bytes'], # write bytes
|
| 1927 |
+
fields[b'rchar'], # read chars
|
| 1928 |
+
fields[b'wchar'], # write chars
|
| 1929 |
+
)
|
| 1930 |
+
except KeyError as err:
|
| 1931 |
+
raise ValueError(
|
| 1932 |
+
"%r field was not found in %s; found fields are %r"
|
| 1933 |
+
% (err.args[0], fname, fields)
|
| 1934 |
+
)
|
| 1935 |
+
|
| 1936 |
+
@wrap_exceptions
|
| 1937 |
+
def cpu_times(self):
|
| 1938 |
+
values = self._parse_stat_file()
|
| 1939 |
+
utime = float(values['utime']) / CLOCK_TICKS
|
| 1940 |
+
stime = float(values['stime']) / CLOCK_TICKS
|
| 1941 |
+
children_utime = float(values['children_utime']) / CLOCK_TICKS
|
| 1942 |
+
children_stime = float(values['children_stime']) / CLOCK_TICKS
|
| 1943 |
+
iowait = float(values['blkio_ticks']) / CLOCK_TICKS
|
| 1944 |
+
return pcputimes(utime, stime, children_utime, children_stime, iowait)
|
| 1945 |
+
|
| 1946 |
+
@wrap_exceptions
|
| 1947 |
+
def cpu_num(self):
|
| 1948 |
+
"""What CPU the process is on."""
|
| 1949 |
+
return int(self._parse_stat_file()['cpu_num'])
|
| 1950 |
+
|
| 1951 |
+
@wrap_exceptions
|
| 1952 |
+
def wait(self, timeout=None):
|
| 1953 |
+
return _psposix.wait_pid(self.pid, timeout, self._name)
|
| 1954 |
+
|
| 1955 |
+
@wrap_exceptions
|
| 1956 |
+
def create_time(self):
|
| 1957 |
+
ctime = float(self._parse_stat_file()['create_time'])
|
| 1958 |
+
# According to documentation, starttime is in field 21 and the
|
| 1959 |
+
# unit is jiffies (clock ticks).
|
| 1960 |
+
# We first divide it for clock ticks and then add uptime returning
|
| 1961 |
+
# seconds since the epoch.
|
| 1962 |
+
# Also use cached value if available.
|
| 1963 |
+
bt = BOOT_TIME or boot_time()
|
| 1964 |
+
return (ctime / CLOCK_TICKS) + bt
|
| 1965 |
+
|
| 1966 |
+
@wrap_exceptions
|
| 1967 |
+
def memory_info(self):
|
| 1968 |
+
# ============================================================
|
| 1969 |
+
# | FIELD | DESCRIPTION | AKA | TOP |
|
| 1970 |
+
# ============================================================
|
| 1971 |
+
# | rss | resident set size | | RES |
|
| 1972 |
+
# | vms | total program size | size | VIRT |
|
| 1973 |
+
# | shared | shared pages (from shared mappings) | | SHR |
|
| 1974 |
+
# | text | text ('code') | trs | CODE |
|
| 1975 |
+
# | lib | library (unused in Linux 2.6) | lrs | |
|
| 1976 |
+
# | data | data + stack | drs | DATA |
|
| 1977 |
+
# | dirty | dirty pages (unused in Linux 2.6) | dt | |
|
| 1978 |
+
# ============================================================
|
| 1979 |
+
with open_binary("%s/%s/statm" % (self._procfs_path, self.pid)) as f:
|
| 1980 |
+
vms, rss, shared, text, lib, data, dirty = (
|
| 1981 |
+
int(x) * PAGESIZE for x in f.readline().split()[:7]
|
| 1982 |
+
)
|
| 1983 |
+
return pmem(rss, vms, shared, text, lib, data, dirty)
|
| 1984 |
+
|
| 1985 |
+
if HAS_PROC_SMAPS_ROLLUP or HAS_PROC_SMAPS:
|
| 1986 |
+
|
| 1987 |
+
def _parse_smaps_rollup(self):
|
| 1988 |
+
# /proc/pid/smaps_rollup was added to Linux in 2017. Faster
|
| 1989 |
+
# than /proc/pid/smaps. It reports higher PSS than */smaps
|
| 1990 |
+
# (from 1k up to 200k higher; tested against all processes).
|
| 1991 |
+
# IMPORTANT: /proc/pid/smaps_rollup is weird, because it
|
| 1992 |
+
# raises ESRCH / ENOENT for many PIDs, even if they're alive
|
| 1993 |
+
# (also as root). In that case we'll use /proc/pid/smaps as
|
| 1994 |
+
# fallback, which is slower but has a +50% success rate
|
| 1995 |
+
# compared to /proc/pid/smaps_rollup.
|
| 1996 |
+
uss = pss = swap = 0
|
| 1997 |
+
with open_binary(
|
| 1998 |
+
"{}/{}/smaps_rollup".format(self._procfs_path, self.pid)
|
| 1999 |
+
) as f:
|
| 2000 |
+
for line in f:
|
| 2001 |
+
if line.startswith(b"Private_"):
|
| 2002 |
+
# Private_Clean, Private_Dirty, Private_Hugetlb
|
| 2003 |
+
uss += int(line.split()[1]) * 1024
|
| 2004 |
+
elif line.startswith(b"Pss:"):
|
| 2005 |
+
pss = int(line.split()[1]) * 1024
|
| 2006 |
+
elif line.startswith(b"Swap:"):
|
| 2007 |
+
swap = int(line.split()[1]) * 1024
|
| 2008 |
+
return (uss, pss, swap)
|
| 2009 |
+
|
| 2010 |
+
@wrap_exceptions
|
| 2011 |
+
def _parse_smaps(
|
| 2012 |
+
self,
|
| 2013 |
+
# Gets Private_Clean, Private_Dirty, Private_Hugetlb.
|
| 2014 |
+
_private_re=re.compile(br"\nPrivate.*:\s+(\d+)"),
|
| 2015 |
+
_pss_re=re.compile(br"\nPss\:\s+(\d+)"),
|
| 2016 |
+
_swap_re=re.compile(br"\nSwap\:\s+(\d+)"),
|
| 2017 |
+
):
|
| 2018 |
+
# /proc/pid/smaps does not exist on kernels < 2.6.14 or if
|
| 2019 |
+
# CONFIG_MMU kernel configuration option is not enabled.
|
| 2020 |
+
|
| 2021 |
+
# Note: using 3 regexes is faster than reading the file
|
| 2022 |
+
# line by line.
|
| 2023 |
+
# XXX: on Python 3 the 2 regexes are 30% slower than on
|
| 2024 |
+
# Python 2 though. Figure out why.
|
| 2025 |
+
#
|
| 2026 |
+
# You might be tempted to calculate USS by subtracting
|
| 2027 |
+
# the "shared" value from the "resident" value in
|
| 2028 |
+
# /proc/<pid>/statm. But at least on Linux, statm's "shared"
|
| 2029 |
+
# value actually counts pages backed by files, which has
|
| 2030 |
+
# little to do with whether the pages are actually shared.
|
| 2031 |
+
# /proc/self/smaps on the other hand appears to give us the
|
| 2032 |
+
# correct information.
|
| 2033 |
+
smaps_data = self._read_smaps_file()
|
| 2034 |
+
# Note: smaps file can be empty for certain processes.
|
| 2035 |
+
# The code below will not crash though and will result to 0.
|
| 2036 |
+
uss = sum(map(int, _private_re.findall(smaps_data))) * 1024
|
| 2037 |
+
pss = sum(map(int, _pss_re.findall(smaps_data))) * 1024
|
| 2038 |
+
swap = sum(map(int, _swap_re.findall(smaps_data))) * 1024
|
| 2039 |
+
return (uss, pss, swap)
|
| 2040 |
+
|
| 2041 |
+
@wrap_exceptions
|
| 2042 |
+
def memory_full_info(self):
|
| 2043 |
+
if HAS_PROC_SMAPS_ROLLUP: # faster
|
| 2044 |
+
try:
|
| 2045 |
+
uss, pss, swap = self._parse_smaps_rollup()
|
| 2046 |
+
except (ProcessLookupError, FileNotFoundError):
|
| 2047 |
+
uss, pss, swap = self._parse_smaps()
|
| 2048 |
+
else:
|
| 2049 |
+
uss, pss, swap = self._parse_smaps()
|
| 2050 |
+
basic_mem = self.memory_info()
|
| 2051 |
+
return pfullmem(*basic_mem + (uss, pss, swap))
|
| 2052 |
+
|
| 2053 |
+
else:
|
| 2054 |
+
memory_full_info = memory_info
|
| 2055 |
+
|
| 2056 |
+
if HAS_PROC_SMAPS:
|
| 2057 |
+
|
| 2058 |
+
@wrap_exceptions
|
| 2059 |
+
def memory_maps(self):
|
| 2060 |
+
"""Return process's mapped memory regions as a list of named
|
| 2061 |
+
tuples. Fields are explained in 'man proc'; here is an updated
|
| 2062 |
+
(Apr 2012) version: http://goo.gl/fmebo.
|
| 2063 |
+
|
| 2064 |
+
/proc/{PID}/smaps does not exist on kernels < 2.6.14 or if
|
| 2065 |
+
CONFIG_MMU kernel configuration option is not enabled.
|
| 2066 |
+
"""
|
| 2067 |
+
|
| 2068 |
+
def get_blocks(lines, current_block):
|
| 2069 |
+
data = {}
|
| 2070 |
+
for line in lines:
|
| 2071 |
+
fields = line.split(None, 5)
|
| 2072 |
+
if not fields[0].endswith(b':'):
|
| 2073 |
+
# new block section
|
| 2074 |
+
yield (current_block.pop(), data)
|
| 2075 |
+
current_block.append(line)
|
| 2076 |
+
else:
|
| 2077 |
+
try:
|
| 2078 |
+
data[fields[0]] = int(fields[1]) * 1024
|
| 2079 |
+
except ValueError:
|
| 2080 |
+
if fields[0].startswith(b'VmFlags:'):
|
| 2081 |
+
# see issue #369
|
| 2082 |
+
continue
|
| 2083 |
+
else:
|
| 2084 |
+
raise ValueError(
|
| 2085 |
+
"don't know how to interpret line %r"
|
| 2086 |
+
% line
|
| 2087 |
+
)
|
| 2088 |
+
yield (current_block.pop(), data)
|
| 2089 |
+
|
| 2090 |
+
data = self._read_smaps_file()
|
| 2091 |
+
# Note: smaps file can be empty for certain processes or for
|
| 2092 |
+
# zombies.
|
| 2093 |
+
if not data:
|
| 2094 |
+
self._raise_if_zombie()
|
| 2095 |
+
return []
|
| 2096 |
+
lines = data.split(b'\n')
|
| 2097 |
+
ls = []
|
| 2098 |
+
first_line = lines.pop(0)
|
| 2099 |
+
current_block = [first_line]
|
| 2100 |
+
for header, data in get_blocks(lines, current_block):
|
| 2101 |
+
hfields = header.split(None, 5)
|
| 2102 |
+
try:
|
| 2103 |
+
addr, perms, _offset, _dev, _inode, path = hfields
|
| 2104 |
+
except ValueError:
|
| 2105 |
+
addr, perms, _offset, _dev, _inode, path = hfields + ['']
|
| 2106 |
+
if not path:
|
| 2107 |
+
path = '[anon]'
|
| 2108 |
+
else:
|
| 2109 |
+
if PY3:
|
| 2110 |
+
path = decode(path)
|
| 2111 |
+
path = path.strip()
|
| 2112 |
+
if path.endswith(' (deleted)') and not path_exists_strict(
|
| 2113 |
+
path
|
| 2114 |
+
):
|
| 2115 |
+
path = path[:-10]
|
| 2116 |
+
item = (
|
| 2117 |
+
decode(addr),
|
| 2118 |
+
decode(perms),
|
| 2119 |
+
path,
|
| 2120 |
+
data.get(b'Rss:', 0),
|
| 2121 |
+
data.get(b'Size:', 0),
|
| 2122 |
+
data.get(b'Pss:', 0),
|
| 2123 |
+
data.get(b'Shared_Clean:', 0),
|
| 2124 |
+
data.get(b'Shared_Dirty:', 0),
|
| 2125 |
+
data.get(b'Private_Clean:', 0),
|
| 2126 |
+
data.get(b'Private_Dirty:', 0),
|
| 2127 |
+
data.get(b'Referenced:', 0),
|
| 2128 |
+
data.get(b'Anonymous:', 0),
|
| 2129 |
+
data.get(b'Swap:', 0),
|
| 2130 |
+
)
|
| 2131 |
+
ls.append(item)
|
| 2132 |
+
return ls
|
| 2133 |
+
|
| 2134 |
+
@wrap_exceptions
|
| 2135 |
+
def cwd(self):
|
| 2136 |
+
return readlink("%s/%s/cwd" % (self._procfs_path, self.pid))
|
| 2137 |
+
|
| 2138 |
+
@wrap_exceptions
|
| 2139 |
+
def num_ctx_switches(
|
| 2140 |
+
self, _ctxsw_re=re.compile(br'ctxt_switches:\t(\d+)')
|
| 2141 |
+
):
|
| 2142 |
+
data = self._read_status_file()
|
| 2143 |
+
ctxsw = _ctxsw_re.findall(data)
|
| 2144 |
+
if not ctxsw:
|
| 2145 |
+
raise NotImplementedError(
|
| 2146 |
+
"'voluntary_ctxt_switches' and 'nonvoluntary_ctxt_switches'"
|
| 2147 |
+
"lines were not found in %s/%s/status; the kernel is "
|
| 2148 |
+
"probably older than 2.6.23" % (self._procfs_path, self.pid)
|
| 2149 |
+
)
|
| 2150 |
+
else:
|
| 2151 |
+
return _common.pctxsw(int(ctxsw[0]), int(ctxsw[1]))
|
| 2152 |
+
|
| 2153 |
+
@wrap_exceptions
|
| 2154 |
+
def num_threads(self, _num_threads_re=re.compile(br'Threads:\t(\d+)')):
|
| 2155 |
+
# Note: on Python 3 using a re is faster than iterating over file
|
| 2156 |
+
# line by line. On Python 2 is the exact opposite, and iterating
|
| 2157 |
+
# over a file on Python 3 is slower than on Python 2.
|
| 2158 |
+
data = self._read_status_file()
|
| 2159 |
+
return int(_num_threads_re.findall(data)[0])
|
| 2160 |
+
|
| 2161 |
+
@wrap_exceptions
|
| 2162 |
+
def threads(self):
|
| 2163 |
+
thread_ids = os.listdir("%s/%s/task" % (self._procfs_path, self.pid))
|
| 2164 |
+
thread_ids.sort()
|
| 2165 |
+
retlist = []
|
| 2166 |
+
hit_enoent = False
|
| 2167 |
+
for thread_id in thread_ids:
|
| 2168 |
+
fname = "%s/%s/task/%s/stat" % (
|
| 2169 |
+
self._procfs_path,
|
| 2170 |
+
self.pid,
|
| 2171 |
+
thread_id,
|
| 2172 |
+
)
|
| 2173 |
+
try:
|
| 2174 |
+
with open_binary(fname) as f:
|
| 2175 |
+
st = f.read().strip()
|
| 2176 |
+
except (FileNotFoundError, ProcessLookupError):
|
| 2177 |
+
# no such file or directory or no such process;
|
| 2178 |
+
# it means thread disappeared on us
|
| 2179 |
+
hit_enoent = True
|
| 2180 |
+
continue
|
| 2181 |
+
# ignore the first two values ("pid (exe)")
|
| 2182 |
+
st = st[st.find(b')') + 2 :]
|
| 2183 |
+
values = st.split(b' ')
|
| 2184 |
+
utime = float(values[11]) / CLOCK_TICKS
|
| 2185 |
+
stime = float(values[12]) / CLOCK_TICKS
|
| 2186 |
+
ntuple = _common.pthread(int(thread_id), utime, stime)
|
| 2187 |
+
retlist.append(ntuple)
|
| 2188 |
+
if hit_enoent:
|
| 2189 |
+
self._raise_if_not_alive()
|
| 2190 |
+
return retlist
|
| 2191 |
+
|
| 2192 |
+
@wrap_exceptions
|
| 2193 |
+
def nice_get(self):
|
| 2194 |
+
# with open_text('%s/%s/stat' % (self._procfs_path, self.pid)) as f:
|
| 2195 |
+
# data = f.read()
|
| 2196 |
+
# return int(data.split()[18])
|
| 2197 |
+
|
| 2198 |
+
# Use C implementation
|
| 2199 |
+
return cext_posix.getpriority(self.pid)
|
| 2200 |
+
|
| 2201 |
+
@wrap_exceptions
|
| 2202 |
+
def nice_set(self, value):
|
| 2203 |
+
return cext_posix.setpriority(self.pid, value)
|
| 2204 |
+
|
| 2205 |
+
# starting from CentOS 6.
|
| 2206 |
+
if HAS_CPU_AFFINITY:
|
| 2207 |
+
|
| 2208 |
+
@wrap_exceptions
|
| 2209 |
+
def cpu_affinity_get(self):
|
| 2210 |
+
return cext.proc_cpu_affinity_get(self.pid)
|
| 2211 |
+
|
| 2212 |
+
def _get_eligible_cpus(
|
| 2213 |
+
self, _re=re.compile(br"Cpus_allowed_list:\t(\d+)-(\d+)")
|
| 2214 |
+
):
|
| 2215 |
+
# See: https://github.com/giampaolo/psutil/issues/956
|
| 2216 |
+
data = self._read_status_file()
|
| 2217 |
+
match = _re.findall(data)
|
| 2218 |
+
if match:
|
| 2219 |
+
return list(range(int(match[0][0]), int(match[0][1]) + 1))
|
| 2220 |
+
else:
|
| 2221 |
+
return list(range(len(per_cpu_times())))
|
| 2222 |
+
|
| 2223 |
+
@wrap_exceptions
|
| 2224 |
+
def cpu_affinity_set(self, cpus):
|
| 2225 |
+
try:
|
| 2226 |
+
cext.proc_cpu_affinity_set(self.pid, cpus)
|
| 2227 |
+
except (OSError, ValueError) as err:
|
| 2228 |
+
if isinstance(err, ValueError) or err.errno == errno.EINVAL:
|
| 2229 |
+
eligible_cpus = self._get_eligible_cpus()
|
| 2230 |
+
all_cpus = tuple(range(len(per_cpu_times())))
|
| 2231 |
+
for cpu in cpus:
|
| 2232 |
+
if cpu not in all_cpus:
|
| 2233 |
+
raise ValueError(
|
| 2234 |
+
"invalid CPU number %r; choose between %s"
|
| 2235 |
+
% (cpu, eligible_cpus)
|
| 2236 |
+
)
|
| 2237 |
+
if cpu not in eligible_cpus:
|
| 2238 |
+
raise ValueError(
|
| 2239 |
+
"CPU number %r is not eligible; choose "
|
| 2240 |
+
"between %s" % (cpu, eligible_cpus)
|
| 2241 |
+
)
|
| 2242 |
+
raise
|
| 2243 |
+
|
| 2244 |
+
# only starting from kernel 2.6.13
|
| 2245 |
+
if HAS_PROC_IO_PRIORITY:
|
| 2246 |
+
|
| 2247 |
+
@wrap_exceptions
|
| 2248 |
+
def ionice_get(self):
|
| 2249 |
+
ioclass, value = cext.proc_ioprio_get(self.pid)
|
| 2250 |
+
if enum is not None:
|
| 2251 |
+
ioclass = IOPriority(ioclass)
|
| 2252 |
+
return _common.pionice(ioclass, value)
|
| 2253 |
+
|
| 2254 |
+
@wrap_exceptions
|
| 2255 |
+
def ionice_set(self, ioclass, value):
|
| 2256 |
+
if value is None:
|
| 2257 |
+
value = 0
|
| 2258 |
+
if value and ioclass in {IOPRIO_CLASS_IDLE, IOPRIO_CLASS_NONE}:
|
| 2259 |
+
raise ValueError("%r ioclass accepts no value" % ioclass)
|
| 2260 |
+
if value < 0 or value > 7:
|
| 2261 |
+
msg = "value not in 0-7 range"
|
| 2262 |
+
raise ValueError(msg)
|
| 2263 |
+
return cext.proc_ioprio_set(self.pid, ioclass, value)
|
| 2264 |
+
|
| 2265 |
+
if prlimit is not None:
|
| 2266 |
+
|
| 2267 |
+
@wrap_exceptions
|
| 2268 |
+
def rlimit(self, resource_, limits=None):
|
| 2269 |
+
# If pid is 0 prlimit() applies to the calling process and
|
| 2270 |
+
# we don't want that. We should never get here though as
|
| 2271 |
+
# PID 0 is not supported on Linux.
|
| 2272 |
+
if self.pid == 0:
|
| 2273 |
+
msg = "can't use prlimit() against PID 0 process"
|
| 2274 |
+
raise ValueError(msg)
|
| 2275 |
+
try:
|
| 2276 |
+
if limits is None:
|
| 2277 |
+
# get
|
| 2278 |
+
return prlimit(self.pid, resource_)
|
| 2279 |
+
else:
|
| 2280 |
+
# set
|
| 2281 |
+
if len(limits) != 2:
|
| 2282 |
+
msg = (
|
| 2283 |
+
"second argument must be a (soft, hard) "
|
| 2284 |
+
+ "tuple, got %s" % repr(limits)
|
| 2285 |
+
)
|
| 2286 |
+
raise ValueError(msg)
|
| 2287 |
+
prlimit(self.pid, resource_, limits)
|
| 2288 |
+
except OSError as err:
|
| 2289 |
+
if err.errno == errno.ENOSYS:
|
| 2290 |
+
# I saw this happening on Travis:
|
| 2291 |
+
# https://travis-ci.org/giampaolo/psutil/jobs/51368273
|
| 2292 |
+
self._raise_if_zombie()
|
| 2293 |
+
raise
|
| 2294 |
+
|
| 2295 |
+
@wrap_exceptions
|
| 2296 |
+
def status(self):
|
| 2297 |
+
letter = self._parse_stat_file()['status']
|
| 2298 |
+
if PY3:
|
| 2299 |
+
letter = letter.decode()
|
| 2300 |
+
# XXX is '?' legit? (we're not supposed to return it anyway)
|
| 2301 |
+
return PROC_STATUSES.get(letter, '?')
|
| 2302 |
+
|
| 2303 |
+
@wrap_exceptions
|
| 2304 |
+
def open_files(self):
|
| 2305 |
+
retlist = []
|
| 2306 |
+
files = os.listdir("%s/%s/fd" % (self._procfs_path, self.pid))
|
| 2307 |
+
hit_enoent = False
|
| 2308 |
+
for fd in files:
|
| 2309 |
+
file = "%s/%s/fd/%s" % (self._procfs_path, self.pid, fd)
|
| 2310 |
+
try:
|
| 2311 |
+
path = readlink(file)
|
| 2312 |
+
except (FileNotFoundError, ProcessLookupError):
|
| 2313 |
+
# ENOENT == file which is gone in the meantime
|
| 2314 |
+
hit_enoent = True
|
| 2315 |
+
continue
|
| 2316 |
+
except OSError as err:
|
| 2317 |
+
if err.errno == errno.EINVAL:
|
| 2318 |
+
# not a link
|
| 2319 |
+
continue
|
| 2320 |
+
if err.errno == errno.ENAMETOOLONG:
|
| 2321 |
+
# file name too long
|
| 2322 |
+
debug(err)
|
| 2323 |
+
continue
|
| 2324 |
+
raise
|
| 2325 |
+
else:
|
| 2326 |
+
# If path is not an absolute there's no way to tell
|
| 2327 |
+
# whether it's a regular file or not, so we skip it.
|
| 2328 |
+
# A regular file is always supposed to be have an
|
| 2329 |
+
# absolute path though.
|
| 2330 |
+
if path.startswith('/') and isfile_strict(path):
|
| 2331 |
+
# Get file position and flags.
|
| 2332 |
+
file = "%s/%s/fdinfo/%s" % (
|
| 2333 |
+
self._procfs_path,
|
| 2334 |
+
self.pid,
|
| 2335 |
+
fd,
|
| 2336 |
+
)
|
| 2337 |
+
try:
|
| 2338 |
+
with open_binary(file) as f:
|
| 2339 |
+
pos = int(f.readline().split()[1])
|
| 2340 |
+
flags = int(f.readline().split()[1], 8)
|
| 2341 |
+
except (FileNotFoundError, ProcessLookupError):
|
| 2342 |
+
# fd gone in the meantime; process may
|
| 2343 |
+
# still be alive
|
| 2344 |
+
hit_enoent = True
|
| 2345 |
+
else:
|
| 2346 |
+
mode = file_flags_to_mode(flags)
|
| 2347 |
+
ntuple = popenfile(
|
| 2348 |
+
path, int(fd), int(pos), mode, flags
|
| 2349 |
+
)
|
| 2350 |
+
retlist.append(ntuple)
|
| 2351 |
+
if hit_enoent:
|
| 2352 |
+
self._raise_if_not_alive()
|
| 2353 |
+
return retlist
|
| 2354 |
+
|
| 2355 |
+
@wrap_exceptions
|
| 2356 |
+
def net_connections(self, kind='inet'):
|
| 2357 |
+
ret = _net_connections.retrieve(kind, self.pid)
|
| 2358 |
+
self._raise_if_not_alive()
|
| 2359 |
+
return ret
|
| 2360 |
+
|
| 2361 |
+
@wrap_exceptions
|
| 2362 |
+
def num_fds(self):
|
| 2363 |
+
return len(os.listdir("%s/%s/fd" % (self._procfs_path, self.pid)))
|
| 2364 |
+
|
| 2365 |
+
@wrap_exceptions
|
| 2366 |
+
def ppid(self):
|
| 2367 |
+
return int(self._parse_stat_file()['ppid'])
|
| 2368 |
+
|
| 2369 |
+
@wrap_exceptions
|
| 2370 |
+
def uids(self, _uids_re=re.compile(br'Uid:\t(\d+)\t(\d+)\t(\d+)')):
|
| 2371 |
+
data = self._read_status_file()
|
| 2372 |
+
real, effective, saved = _uids_re.findall(data)[0]
|
| 2373 |
+
return _common.puids(int(real), int(effective), int(saved))
|
| 2374 |
+
|
| 2375 |
+
@wrap_exceptions
|
| 2376 |
+
def gids(self, _gids_re=re.compile(br'Gid:\t(\d+)\t(\d+)\t(\d+)')):
|
| 2377 |
+
data = self._read_status_file()
|
| 2378 |
+
real, effective, saved = _gids_re.findall(data)[0]
|
| 2379 |
+
return _common.pgids(int(real), int(effective), int(saved))
|
mplug_owl2/lib/python3.10/site-packages/psutil/_psosx.py
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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source code is governed by a BSD-style license that can be
|
| 3 |
+
# found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
"""macOS platform implementation."""
|
| 6 |
+
|
| 7 |
+
import errno
|
| 8 |
+
import functools
|
| 9 |
+
import os
|
| 10 |
+
from collections import namedtuple
|
| 11 |
+
|
| 12 |
+
from . import _common
|
| 13 |
+
from . import _psposix
|
| 14 |
+
from . import _psutil_osx as cext
|
| 15 |
+
from . import _psutil_posix as cext_posix
|
| 16 |
+
from ._common import AccessDenied
|
| 17 |
+
from ._common import NoSuchProcess
|
| 18 |
+
from ._common import ZombieProcess
|
| 19 |
+
from ._common import conn_tmap
|
| 20 |
+
from ._common import conn_to_ntuple
|
| 21 |
+
from ._common import isfile_strict
|
| 22 |
+
from ._common import memoize_when_activated
|
| 23 |
+
from ._common import parse_environ_block
|
| 24 |
+
from ._common import usage_percent
|
| 25 |
+
from ._compat import PermissionError
|
| 26 |
+
from ._compat import ProcessLookupError
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__extra__all__ = []
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# =====================================================================
|
| 33 |
+
# --- globals
|
| 34 |
+
# =====================================================================
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
PAGESIZE = cext_posix.getpagesize()
|
| 38 |
+
AF_LINK = cext_posix.AF_LINK
|
| 39 |
+
|
| 40 |
+
TCP_STATUSES = {
|
| 41 |
+
cext.TCPS_ESTABLISHED: _common.CONN_ESTABLISHED,
|
| 42 |
+
cext.TCPS_SYN_SENT: _common.CONN_SYN_SENT,
|
| 43 |
+
cext.TCPS_SYN_RECEIVED: _common.CONN_SYN_RECV,
|
| 44 |
+
cext.TCPS_FIN_WAIT_1: _common.CONN_FIN_WAIT1,
|
| 45 |
+
cext.TCPS_FIN_WAIT_2: _common.CONN_FIN_WAIT2,
|
| 46 |
+
cext.TCPS_TIME_WAIT: _common.CONN_TIME_WAIT,
|
| 47 |
+
cext.TCPS_CLOSED: _common.CONN_CLOSE,
|
| 48 |
+
cext.TCPS_CLOSE_WAIT: _common.CONN_CLOSE_WAIT,
|
| 49 |
+
cext.TCPS_LAST_ACK: _common.CONN_LAST_ACK,
|
| 50 |
+
cext.TCPS_LISTEN: _common.CONN_LISTEN,
|
| 51 |
+
cext.TCPS_CLOSING: _common.CONN_CLOSING,
|
| 52 |
+
cext.PSUTIL_CONN_NONE: _common.CONN_NONE,
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
PROC_STATUSES = {
|
| 56 |
+
cext.SIDL: _common.STATUS_IDLE,
|
| 57 |
+
cext.SRUN: _common.STATUS_RUNNING,
|
| 58 |
+
cext.SSLEEP: _common.STATUS_SLEEPING,
|
| 59 |
+
cext.SSTOP: _common.STATUS_STOPPED,
|
| 60 |
+
cext.SZOMB: _common.STATUS_ZOMBIE,
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
kinfo_proc_map = dict(
|
| 64 |
+
ppid=0,
|
| 65 |
+
ruid=1,
|
| 66 |
+
euid=2,
|
| 67 |
+
suid=3,
|
| 68 |
+
rgid=4,
|
| 69 |
+
egid=5,
|
| 70 |
+
sgid=6,
|
| 71 |
+
ttynr=7,
|
| 72 |
+
ctime=8,
|
| 73 |
+
status=9,
|
| 74 |
+
name=10,
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
pidtaskinfo_map = dict(
|
| 78 |
+
cpuutime=0,
|
| 79 |
+
cpustime=1,
|
| 80 |
+
rss=2,
|
| 81 |
+
vms=3,
|
| 82 |
+
pfaults=4,
|
| 83 |
+
pageins=5,
|
| 84 |
+
numthreads=6,
|
| 85 |
+
volctxsw=7,
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# =====================================================================
|
| 90 |
+
# --- named tuples
|
| 91 |
+
# =====================================================================
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
# fmt: off
|
| 95 |
+
# psutil.cpu_times()
|
| 96 |
+
scputimes = namedtuple('scputimes', ['user', 'nice', 'system', 'idle'])
|
| 97 |
+
# psutil.virtual_memory()
|
| 98 |
+
svmem = namedtuple(
|
| 99 |
+
'svmem', ['total', 'available', 'percent', 'used', 'free',
|
| 100 |
+
'active', 'inactive', 'wired'])
|
| 101 |
+
# psutil.Process.memory_info()
|
| 102 |
+
pmem = namedtuple('pmem', ['rss', 'vms', 'pfaults', 'pageins'])
|
| 103 |
+
# psutil.Process.memory_full_info()
|
| 104 |
+
pfullmem = namedtuple('pfullmem', pmem._fields + ('uss', ))
|
| 105 |
+
# fmt: on
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
# =====================================================================
|
| 109 |
+
# --- memory
|
| 110 |
+
# =====================================================================
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def virtual_memory():
|
| 114 |
+
"""System virtual memory as a namedtuple."""
|
| 115 |
+
total, active, inactive, wired, free, speculative = cext.virtual_mem()
|
| 116 |
+
# This is how Zabbix calculate avail and used mem:
|
| 117 |
+
# https://github.com/zabbix/zabbix/blob/trunk/src/libs/zbxsysinfo/
|
| 118 |
+
# osx/memory.c
|
| 119 |
+
# Also see: https://github.com/giampaolo/psutil/issues/1277
|
| 120 |
+
avail = inactive + free
|
| 121 |
+
used = active + wired
|
| 122 |
+
# This is NOT how Zabbix calculates free mem but it matches "free"
|
| 123 |
+
# cmdline utility.
|
| 124 |
+
free -= speculative
|
| 125 |
+
percent = usage_percent((total - avail), total, round_=1)
|
| 126 |
+
return svmem(total, avail, percent, used, free, active, inactive, wired)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def swap_memory():
|
| 130 |
+
"""Swap system memory as a (total, used, free, sin, sout) tuple."""
|
| 131 |
+
total, used, free, sin, sout = cext.swap_mem()
|
| 132 |
+
percent = usage_percent(used, total, round_=1)
|
| 133 |
+
return _common.sswap(total, used, free, percent, sin, sout)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
# =====================================================================
|
| 137 |
+
# --- CPU
|
| 138 |
+
# =====================================================================
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def cpu_times():
|
| 142 |
+
"""Return system CPU times as a namedtuple."""
|
| 143 |
+
user, nice, system, idle = cext.cpu_times()
|
| 144 |
+
return scputimes(user, nice, system, idle)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def per_cpu_times():
|
| 148 |
+
"""Return system CPU times as a named tuple."""
|
| 149 |
+
ret = []
|
| 150 |
+
for cpu_t in cext.per_cpu_times():
|
| 151 |
+
user, nice, system, idle = cpu_t
|
| 152 |
+
item = scputimes(user, nice, system, idle)
|
| 153 |
+
ret.append(item)
|
| 154 |
+
return ret
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def cpu_count_logical():
|
| 158 |
+
"""Return the number of logical CPUs in the system."""
|
| 159 |
+
return cext.cpu_count_logical()
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def cpu_count_cores():
|
| 163 |
+
"""Return the number of CPU cores in the system."""
|
| 164 |
+
return cext.cpu_count_cores()
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def cpu_stats():
|
| 168 |
+
ctx_switches, interrupts, soft_interrupts, syscalls, _traps = (
|
| 169 |
+
cext.cpu_stats()
|
| 170 |
+
)
|
| 171 |
+
return _common.scpustats(
|
| 172 |
+
ctx_switches, interrupts, soft_interrupts, syscalls
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def cpu_freq():
|
| 177 |
+
"""Return CPU frequency.
|
| 178 |
+
On macOS per-cpu frequency is not supported.
|
| 179 |
+
Also, the returned frequency never changes, see:
|
| 180 |
+
https://arstechnica.com/civis/viewtopic.php?f=19&t=465002.
|
| 181 |
+
"""
|
| 182 |
+
curr, min_, max_ = cext.cpu_freq()
|
| 183 |
+
return [_common.scpufreq(curr, min_, max_)]
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
# =====================================================================
|
| 187 |
+
# --- disks
|
| 188 |
+
# =====================================================================
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
disk_usage = _psposix.disk_usage
|
| 192 |
+
disk_io_counters = cext.disk_io_counters
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def disk_partitions(all=False):
|
| 196 |
+
"""Return mounted disk partitions as a list of namedtuples."""
|
| 197 |
+
retlist = []
|
| 198 |
+
partitions = cext.disk_partitions()
|
| 199 |
+
for partition in partitions:
|
| 200 |
+
device, mountpoint, fstype, opts = partition
|
| 201 |
+
if device == 'none':
|
| 202 |
+
device = ''
|
| 203 |
+
if not all:
|
| 204 |
+
if not os.path.isabs(device) or not os.path.exists(device):
|
| 205 |
+
continue
|
| 206 |
+
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
|
| 207 |
+
retlist.append(ntuple)
|
| 208 |
+
return retlist
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
# =====================================================================
|
| 212 |
+
# --- sensors
|
| 213 |
+
# =====================================================================
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def sensors_battery():
|
| 217 |
+
"""Return battery information."""
|
| 218 |
+
try:
|
| 219 |
+
percent, minsleft, power_plugged = cext.sensors_battery()
|
| 220 |
+
except NotImplementedError:
|
| 221 |
+
# no power source - return None according to interface
|
| 222 |
+
return None
|
| 223 |
+
power_plugged = power_plugged == 1
|
| 224 |
+
if power_plugged:
|
| 225 |
+
secsleft = _common.POWER_TIME_UNLIMITED
|
| 226 |
+
elif minsleft == -1:
|
| 227 |
+
secsleft = _common.POWER_TIME_UNKNOWN
|
| 228 |
+
else:
|
| 229 |
+
secsleft = minsleft * 60
|
| 230 |
+
return _common.sbattery(percent, secsleft, power_plugged)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
# =====================================================================
|
| 234 |
+
# --- network
|
| 235 |
+
# =====================================================================
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
net_io_counters = cext.net_io_counters
|
| 239 |
+
net_if_addrs = cext_posix.net_if_addrs
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def net_connections(kind='inet'):
|
| 243 |
+
"""System-wide network connections."""
|
| 244 |
+
# Note: on macOS this will fail with AccessDenied unless
|
| 245 |
+
# the process is owned by root.
|
| 246 |
+
ret = []
|
| 247 |
+
for pid in pids():
|
| 248 |
+
try:
|
| 249 |
+
cons = Process(pid).net_connections(kind)
|
| 250 |
+
except NoSuchProcess:
|
| 251 |
+
continue
|
| 252 |
+
else:
|
| 253 |
+
if cons:
|
| 254 |
+
for c in cons:
|
| 255 |
+
c = list(c) + [pid]
|
| 256 |
+
ret.append(_common.sconn(*c))
|
| 257 |
+
return ret
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def net_if_stats():
|
| 261 |
+
"""Get NIC stats (isup, duplex, speed, mtu)."""
|
| 262 |
+
names = net_io_counters().keys()
|
| 263 |
+
ret = {}
|
| 264 |
+
for name in names:
|
| 265 |
+
try:
|
| 266 |
+
mtu = cext_posix.net_if_mtu(name)
|
| 267 |
+
flags = cext_posix.net_if_flags(name)
|
| 268 |
+
duplex, speed = cext_posix.net_if_duplex_speed(name)
|
| 269 |
+
except OSError as err:
|
| 270 |
+
# https://github.com/giampaolo/psutil/issues/1279
|
| 271 |
+
if err.errno != errno.ENODEV:
|
| 272 |
+
raise
|
| 273 |
+
else:
|
| 274 |
+
if hasattr(_common, 'NicDuplex'):
|
| 275 |
+
duplex = _common.NicDuplex(duplex)
|
| 276 |
+
output_flags = ','.join(flags)
|
| 277 |
+
isup = 'running' in flags
|
| 278 |
+
ret[name] = _common.snicstats(
|
| 279 |
+
isup, duplex, speed, mtu, output_flags
|
| 280 |
+
)
|
| 281 |
+
return ret
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
# =====================================================================
|
| 285 |
+
# --- other system functions
|
| 286 |
+
# =====================================================================
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
def boot_time():
|
| 290 |
+
"""The system boot time expressed in seconds since the epoch."""
|
| 291 |
+
return cext.boot_time()
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def users():
|
| 295 |
+
"""Return currently connected users as a list of namedtuples."""
|
| 296 |
+
retlist = []
|
| 297 |
+
rawlist = cext.users()
|
| 298 |
+
for item in rawlist:
|
| 299 |
+
user, tty, hostname, tstamp, pid = item
|
| 300 |
+
if tty == '~':
|
| 301 |
+
continue # reboot or shutdown
|
| 302 |
+
if not tstamp:
|
| 303 |
+
continue
|
| 304 |
+
nt = _common.suser(user, tty or None, hostname or None, tstamp, pid)
|
| 305 |
+
retlist.append(nt)
|
| 306 |
+
return retlist
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
# =====================================================================
|
| 310 |
+
# --- processes
|
| 311 |
+
# =====================================================================
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
def pids():
|
| 315 |
+
ls = cext.pids()
|
| 316 |
+
if 0 not in ls:
|
| 317 |
+
# On certain macOS versions pids() C doesn't return PID 0 but
|
| 318 |
+
# "ps" does and the process is querable via sysctl():
|
| 319 |
+
# https://travis-ci.org/giampaolo/psutil/jobs/309619941
|
| 320 |
+
try:
|
| 321 |
+
Process(0).create_time()
|
| 322 |
+
ls.insert(0, 0)
|
| 323 |
+
except NoSuchProcess:
|
| 324 |
+
pass
|
| 325 |
+
except AccessDenied:
|
| 326 |
+
ls.insert(0, 0)
|
| 327 |
+
return ls
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
pid_exists = _psposix.pid_exists
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
def is_zombie(pid):
|
| 334 |
+
try:
|
| 335 |
+
st = cext.proc_kinfo_oneshot(pid)[kinfo_proc_map['status']]
|
| 336 |
+
return st == cext.SZOMB
|
| 337 |
+
except OSError:
|
| 338 |
+
return False
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
def wrap_exceptions(fun):
|
| 342 |
+
"""Decorator which translates bare OSError exceptions into
|
| 343 |
+
NoSuchProcess and AccessDenied.
|
| 344 |
+
"""
|
| 345 |
+
|
| 346 |
+
@functools.wraps(fun)
|
| 347 |
+
def wrapper(self, *args, **kwargs):
|
| 348 |
+
try:
|
| 349 |
+
return fun(self, *args, **kwargs)
|
| 350 |
+
except ProcessLookupError:
|
| 351 |
+
if is_zombie(self.pid):
|
| 352 |
+
raise ZombieProcess(self.pid, self._name, self._ppid)
|
| 353 |
+
else:
|
| 354 |
+
raise NoSuchProcess(self.pid, self._name)
|
| 355 |
+
except PermissionError:
|
| 356 |
+
raise AccessDenied(self.pid, self._name)
|
| 357 |
+
|
| 358 |
+
return wrapper
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
class Process:
|
| 362 |
+
"""Wrapper class around underlying C implementation."""
|
| 363 |
+
|
| 364 |
+
__slots__ = ["_cache", "_name", "_ppid", "pid"]
|
| 365 |
+
|
| 366 |
+
def __init__(self, pid):
|
| 367 |
+
self.pid = pid
|
| 368 |
+
self._name = None
|
| 369 |
+
self._ppid = None
|
| 370 |
+
|
| 371 |
+
@wrap_exceptions
|
| 372 |
+
@memoize_when_activated
|
| 373 |
+
def _get_kinfo_proc(self):
|
| 374 |
+
# Note: should work with all PIDs without permission issues.
|
| 375 |
+
ret = cext.proc_kinfo_oneshot(self.pid)
|
| 376 |
+
assert len(ret) == len(kinfo_proc_map)
|
| 377 |
+
return ret
|
| 378 |
+
|
| 379 |
+
@wrap_exceptions
|
| 380 |
+
@memoize_when_activated
|
| 381 |
+
def _get_pidtaskinfo(self):
|
| 382 |
+
# Note: should work for PIDs owned by user only.
|
| 383 |
+
ret = cext.proc_pidtaskinfo_oneshot(self.pid)
|
| 384 |
+
assert len(ret) == len(pidtaskinfo_map)
|
| 385 |
+
return ret
|
| 386 |
+
|
| 387 |
+
def oneshot_enter(self):
|
| 388 |
+
self._get_kinfo_proc.cache_activate(self)
|
| 389 |
+
self._get_pidtaskinfo.cache_activate(self)
|
| 390 |
+
|
| 391 |
+
def oneshot_exit(self):
|
| 392 |
+
self._get_kinfo_proc.cache_deactivate(self)
|
| 393 |
+
self._get_pidtaskinfo.cache_deactivate(self)
|
| 394 |
+
|
| 395 |
+
@wrap_exceptions
|
| 396 |
+
def name(self):
|
| 397 |
+
name = self._get_kinfo_proc()[kinfo_proc_map['name']]
|
| 398 |
+
return name if name is not None else cext.proc_name(self.pid)
|
| 399 |
+
|
| 400 |
+
@wrap_exceptions
|
| 401 |
+
def exe(self):
|
| 402 |
+
return cext.proc_exe(self.pid)
|
| 403 |
+
|
| 404 |
+
@wrap_exceptions
|
| 405 |
+
def cmdline(self):
|
| 406 |
+
return cext.proc_cmdline(self.pid)
|
| 407 |
+
|
| 408 |
+
@wrap_exceptions
|
| 409 |
+
def environ(self):
|
| 410 |
+
return parse_environ_block(cext.proc_environ(self.pid))
|
| 411 |
+
|
| 412 |
+
@wrap_exceptions
|
| 413 |
+
def ppid(self):
|
| 414 |
+
self._ppid = self._get_kinfo_proc()[kinfo_proc_map['ppid']]
|
| 415 |
+
return self._ppid
|
| 416 |
+
|
| 417 |
+
@wrap_exceptions
|
| 418 |
+
def cwd(self):
|
| 419 |
+
return cext.proc_cwd(self.pid)
|
| 420 |
+
|
| 421 |
+
@wrap_exceptions
|
| 422 |
+
def uids(self):
|
| 423 |
+
rawtuple = self._get_kinfo_proc()
|
| 424 |
+
return _common.puids(
|
| 425 |
+
rawtuple[kinfo_proc_map['ruid']],
|
| 426 |
+
rawtuple[kinfo_proc_map['euid']],
|
| 427 |
+
rawtuple[kinfo_proc_map['suid']],
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
@wrap_exceptions
|
| 431 |
+
def gids(self):
|
| 432 |
+
rawtuple = self._get_kinfo_proc()
|
| 433 |
+
return _common.puids(
|
| 434 |
+
rawtuple[kinfo_proc_map['rgid']],
|
| 435 |
+
rawtuple[kinfo_proc_map['egid']],
|
| 436 |
+
rawtuple[kinfo_proc_map['sgid']],
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
@wrap_exceptions
|
| 440 |
+
def terminal(self):
|
| 441 |
+
tty_nr = self._get_kinfo_proc()[kinfo_proc_map['ttynr']]
|
| 442 |
+
tmap = _psposix.get_terminal_map()
|
| 443 |
+
try:
|
| 444 |
+
return tmap[tty_nr]
|
| 445 |
+
except KeyError:
|
| 446 |
+
return None
|
| 447 |
+
|
| 448 |
+
@wrap_exceptions
|
| 449 |
+
def memory_info(self):
|
| 450 |
+
rawtuple = self._get_pidtaskinfo()
|
| 451 |
+
return pmem(
|
| 452 |
+
rawtuple[pidtaskinfo_map['rss']],
|
| 453 |
+
rawtuple[pidtaskinfo_map['vms']],
|
| 454 |
+
rawtuple[pidtaskinfo_map['pfaults']],
|
| 455 |
+
rawtuple[pidtaskinfo_map['pageins']],
|
| 456 |
+
)
|
| 457 |
+
|
| 458 |
+
@wrap_exceptions
|
| 459 |
+
def memory_full_info(self):
|
| 460 |
+
basic_mem = self.memory_info()
|
| 461 |
+
uss = cext.proc_memory_uss(self.pid)
|
| 462 |
+
return pfullmem(*basic_mem + (uss,))
|
| 463 |
+
|
| 464 |
+
@wrap_exceptions
|
| 465 |
+
def cpu_times(self):
|
| 466 |
+
rawtuple = self._get_pidtaskinfo()
|
| 467 |
+
return _common.pcputimes(
|
| 468 |
+
rawtuple[pidtaskinfo_map['cpuutime']],
|
| 469 |
+
rawtuple[pidtaskinfo_map['cpustime']],
|
| 470 |
+
# children user / system times are not retrievable (set to 0)
|
| 471 |
+
0.0,
|
| 472 |
+
0.0,
|
| 473 |
+
)
|
| 474 |
+
|
| 475 |
+
@wrap_exceptions
|
| 476 |
+
def create_time(self):
|
| 477 |
+
return self._get_kinfo_proc()[kinfo_proc_map['ctime']]
|
| 478 |
+
|
| 479 |
+
@wrap_exceptions
|
| 480 |
+
def num_ctx_switches(self):
|
| 481 |
+
# Unvoluntary value seems not to be available;
|
| 482 |
+
# getrusage() numbers seems to confirm this theory.
|
| 483 |
+
# We set it to 0.
|
| 484 |
+
vol = self._get_pidtaskinfo()[pidtaskinfo_map['volctxsw']]
|
| 485 |
+
return _common.pctxsw(vol, 0)
|
| 486 |
+
|
| 487 |
+
@wrap_exceptions
|
| 488 |
+
def num_threads(self):
|
| 489 |
+
return self._get_pidtaskinfo()[pidtaskinfo_map['numthreads']]
|
| 490 |
+
|
| 491 |
+
@wrap_exceptions
|
| 492 |
+
def open_files(self):
|
| 493 |
+
if self.pid == 0:
|
| 494 |
+
return []
|
| 495 |
+
files = []
|
| 496 |
+
rawlist = cext.proc_open_files(self.pid)
|
| 497 |
+
for path, fd in rawlist:
|
| 498 |
+
if isfile_strict(path):
|
| 499 |
+
ntuple = _common.popenfile(path, fd)
|
| 500 |
+
files.append(ntuple)
|
| 501 |
+
return files
|
| 502 |
+
|
| 503 |
+
@wrap_exceptions
|
| 504 |
+
def net_connections(self, kind='inet'):
|
| 505 |
+
if kind not in conn_tmap:
|
| 506 |
+
raise ValueError(
|
| 507 |
+
"invalid %r kind argument; choose between %s"
|
| 508 |
+
% (kind, ', '.join([repr(x) for x in conn_tmap]))
|
| 509 |
+
)
|
| 510 |
+
families, types = conn_tmap[kind]
|
| 511 |
+
rawlist = cext.proc_net_connections(self.pid, families, types)
|
| 512 |
+
ret = []
|
| 513 |
+
for item in rawlist:
|
| 514 |
+
fd, fam, type, laddr, raddr, status = item
|
| 515 |
+
nt = conn_to_ntuple(
|
| 516 |
+
fd, fam, type, laddr, raddr, status, TCP_STATUSES
|
| 517 |
+
)
|
| 518 |
+
ret.append(nt)
|
| 519 |
+
return ret
|
| 520 |
+
|
| 521 |
+
@wrap_exceptions
|
| 522 |
+
def num_fds(self):
|
| 523 |
+
if self.pid == 0:
|
| 524 |
+
return 0
|
| 525 |
+
return cext.proc_num_fds(self.pid)
|
| 526 |
+
|
| 527 |
+
@wrap_exceptions
|
| 528 |
+
def wait(self, timeout=None):
|
| 529 |
+
return _psposix.wait_pid(self.pid, timeout, self._name)
|
| 530 |
+
|
| 531 |
+
@wrap_exceptions
|
| 532 |
+
def nice_get(self):
|
| 533 |
+
return cext_posix.getpriority(self.pid)
|
| 534 |
+
|
| 535 |
+
@wrap_exceptions
|
| 536 |
+
def nice_set(self, value):
|
| 537 |
+
return cext_posix.setpriority(self.pid, value)
|
| 538 |
+
|
| 539 |
+
@wrap_exceptions
|
| 540 |
+
def status(self):
|
| 541 |
+
code = self._get_kinfo_proc()[kinfo_proc_map['status']]
|
| 542 |
+
# XXX is '?' legit? (we're not supposed to return it anyway)
|
| 543 |
+
return PROC_STATUSES.get(code, '?')
|
| 544 |
+
|
| 545 |
+
@wrap_exceptions
|
| 546 |
+
def threads(self):
|
| 547 |
+
rawlist = cext.proc_threads(self.pid)
|
| 548 |
+
retlist = []
|
| 549 |
+
for thread_id, utime, stime in rawlist:
|
| 550 |
+
ntuple = _common.pthread(thread_id, utime, stime)
|
| 551 |
+
retlist.append(ntuple)
|
| 552 |
+
return retlist
|
mplug_owl2/lib/python3.10/site-packages/psutil/_psutil_linux.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2d76b01666546f2806089d6f4ef08f005db0bb410d893a54d463a7b0f8b727e2
|
| 3 |
+
size 115336
|
mplug_owl2/lib/python3.10/site-packages/psutil/_psutil_posix.abi3.so
ADDED
|
Binary file (71.6 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/tests/__pycache__/test_contracts.cpython-310.pyc
ADDED
|
Binary file (13.3 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/tests/__pycache__/test_process.cpython-310.pyc
ADDED
|
Binary file (51.8 kB). View file
|
|
|
mplug_owl2/lib/python3.10/site-packages/psutil/tests/__pycache__/test_process_all.cpython-310.pyc
ADDED
|
Binary file (16.4 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0021.rst
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMP0021
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
Fatal error on relative paths in :prop_tgt:`INCLUDE_DIRECTORIES` target
|
| 5 |
+
property.
|
| 6 |
+
|
| 7 |
+
CMake 2.8.10.2 and lower allowed the :prop_tgt:`INCLUDE_DIRECTORIES` target
|
| 8 |
+
property to contain relative paths. The base path for such relative
|
| 9 |
+
entries is not well defined. CMake 2.8.12 issues a ``FATAL_ERROR`` if the
|
| 10 |
+
:prop_tgt:`INCLUDE_DIRECTORIES` property contains a relative path.
|
| 11 |
+
|
| 12 |
+
The ``OLD`` behavior for this policy is not to warn about relative paths
|
| 13 |
+
in the ``INCLUDE_DIRECTORIES`` target property. The ``NEW`` behavior for this
|
| 14 |
+
policy is to issue a ``FATAL_ERROR`` if ``INCLUDE_DIRECTORIES`` contains a
|
| 15 |
+
relative path.
|
| 16 |
+
|
| 17 |
+
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 2.8.12
|
| 18 |
+
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
| 19 |
+
.. include:: STANDARD_ADVICE.txt
|
| 20 |
+
|
| 21 |
+
.. include:: DEPRECATED.txt
|
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0043.rst
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMP0043
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
Ignore COMPILE_DEFINITIONS_<Config> properties
|
| 5 |
+
|
| 6 |
+
CMake 2.8.12 and lower allowed setting the
|
| 7 |
+
:prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property and
|
| 8 |
+
:prop_dir:`COMPILE_DEFINITIONS_<CONFIG>` directory property to apply
|
| 9 |
+
configuration-specific compile definitions.
|
| 10 |
+
|
| 11 |
+
Since CMake 2.8.10, the :prop_tgt:`COMPILE_DEFINITIONS` property has supported
|
| 12 |
+
:manual:`generator expressions <cmake-generator-expressions(7)>` for setting
|
| 13 |
+
configuration-dependent content. The continued existence of the suffixed
|
| 14 |
+
variables is redundant, and causes a maintenance burden. Population of the
|
| 15 |
+
:prop_tgt:`COMPILE_DEFINITIONS_DEBUG <COMPILE_DEFINITIONS_<CONFIG>>` property
|
| 16 |
+
may be replaced with a population of :prop_tgt:`COMPILE_DEFINITIONS` directly
|
| 17 |
+
or via :command:`target_compile_definitions`:
|
| 18 |
+
|
| 19 |
+
.. code-block:: cmake
|
| 20 |
+
|
| 21 |
+
# Old Interfaces:
|
| 22 |
+
set_property(TARGET tgt APPEND PROPERTY
|
| 23 |
+
COMPILE_DEFINITIONS_DEBUG DEBUG_MODE
|
| 24 |
+
)
|
| 25 |
+
set_property(DIRECTORY APPEND PROPERTY
|
| 26 |
+
COMPILE_DEFINITIONS_DEBUG DIR_DEBUG_MODE
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# New Interfaces:
|
| 30 |
+
set_property(TARGET tgt APPEND PROPERTY
|
| 31 |
+
COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUG_MODE>
|
| 32 |
+
)
|
| 33 |
+
target_compile_definitions(tgt PRIVATE $<$<CONFIG:Debug>:DEBUG_MODE>)
|
| 34 |
+
set_property(DIRECTORY APPEND PROPERTY
|
| 35 |
+
COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DIR_DEBUG_MODE>
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
The ``OLD`` behavior for this policy is to consume the content of the suffixed
|
| 39 |
+
:prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property when generating the
|
| 40 |
+
compilation command. The ``NEW`` behavior for this policy is to ignore the content
|
| 41 |
+
of the :prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property .
|
| 42 |
+
|
| 43 |
+
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.0
|
| 44 |
+
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
| 45 |
+
.. include:: STANDARD_ADVICE.txt
|
| 46 |
+
|
| 47 |
+
.. include:: DEPRECATED.txt
|
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0049.rst
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMP0049
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
Do not expand variables in target source entries.
|
| 5 |
+
|
| 6 |
+
CMake 2.8.12 and lower performed an extra layer of variable expansion
|
| 7 |
+
when evaluating source file names::
|
| 8 |
+
|
| 9 |
+
set(a_source foo.c)
|
| 10 |
+
add_executable(foo \${a_source})
|
| 11 |
+
|
| 12 |
+
.. note: no cmake highlighting since this syntax is deprecated
|
| 13 |
+
|
| 14 |
+
This was undocumented behavior.
|
| 15 |
+
|
| 16 |
+
The ``OLD`` behavior for this policy is to expand such variables when processing
|
| 17 |
+
the target sources. The ``NEW`` behavior for this policy is to issue an error
|
| 18 |
+
if such variables need to be expanded.
|
| 19 |
+
|
| 20 |
+
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.0
|
| 21 |
+
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
| 22 |
+
.. include:: STANDARD_ADVICE.txt
|
| 23 |
+
|
| 24 |
+
.. include:: DEPRECATED.txt
|
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0052.rst
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMP0052
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.1
|
| 5 |
+
|
| 6 |
+
Reject source and build dirs in installed
|
| 7 |
+
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`.
|
| 8 |
+
|
| 9 |
+
CMake 3.0 and lower allowed subdirectories of the source directory or build
|
| 10 |
+
directory to be in the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of
|
| 11 |
+
installed and exported targets, if the directory was also a subdirectory of
|
| 12 |
+
the installation prefix. This makes the installation depend on the
|
| 13 |
+
existence of the source dir or binary dir, and the installation will be
|
| 14 |
+
broken if either are removed after installation.
|
| 15 |
+
|
| 16 |
+
See :ref:`Include Directories and Usage Requirements` for more on
|
| 17 |
+
specifying include directories for targets.
|
| 18 |
+
|
| 19 |
+
The ``OLD`` behavior for this policy is to export the content of the
|
| 20 |
+
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` with the source or binary
|
| 21 |
+
directory. The ``NEW`` behavior for this
|
| 22 |
+
policy is to issue an error if such a directory is used.
|
| 23 |
+
|
| 24 |
+
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.1
|
| 25 |
+
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
| 26 |
+
.. include:: STANDARD_ADVICE.txt
|
| 27 |
+
|
| 28 |
+
.. include:: DEPRECATED.txt
|
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0054.rst
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMP0054
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.1
|
| 5 |
+
|
| 6 |
+
Only interpret :command:`if` arguments as variables or keywords when unquoted.
|
| 7 |
+
|
| 8 |
+
CMake 3.1 and above no longer implicitly dereference variables or
|
| 9 |
+
interpret keywords in an :command:`if` command argument when
|
| 10 |
+
it is a :ref:`Quoted Argument` or a :ref:`Bracket Argument`.
|
| 11 |
+
|
| 12 |
+
The ``OLD`` behavior for this policy is to dereference variables and
|
| 13 |
+
interpret keywords even if they are quoted or bracketed.
|
| 14 |
+
The ``NEW`` behavior is to not dereference variables or interpret keywords
|
| 15 |
+
that have been quoted or bracketed.
|
| 16 |
+
|
| 17 |
+
Given the following partial example:
|
| 18 |
+
|
| 19 |
+
::
|
| 20 |
+
|
| 21 |
+
set(A E)
|
| 22 |
+
set(E "")
|
| 23 |
+
|
| 24 |
+
if("${A}" STREQUAL "")
|
| 25 |
+
message("Result is TRUE before CMake 3.1 or when CMP0054 is OLD")
|
| 26 |
+
else()
|
| 27 |
+
message("Result is FALSE in CMake 3.1 and above if CMP0054 is NEW")
|
| 28 |
+
endif()
|
| 29 |
+
|
| 30 |
+
After explicit expansion of variables this gives:
|
| 31 |
+
|
| 32 |
+
::
|
| 33 |
+
|
| 34 |
+
if("E" STREQUAL "")
|
| 35 |
+
|
| 36 |
+
With the policy set to ``OLD`` implicit expansion reduces this semantically to:
|
| 37 |
+
|
| 38 |
+
::
|
| 39 |
+
|
| 40 |
+
if("" STREQUAL "")
|
| 41 |
+
|
| 42 |
+
With the policy set to ``NEW`` the quoted arguments will not be
|
| 43 |
+
further dereferenced:
|
| 44 |
+
|
| 45 |
+
::
|
| 46 |
+
|
| 47 |
+
if("E" STREQUAL "")
|
| 48 |
+
|
| 49 |
+
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.1
|
| 50 |
+
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
| 51 |
+
.. include:: STANDARD_ADVICE.txt
|
| 52 |
+
|
| 53 |
+
.. include:: DEPRECATED.txt
|
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0058.rst
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMP0058
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.3
|
| 5 |
+
|
| 6 |
+
Ninja requires custom command byproducts to be explicit.
|
| 7 |
+
|
| 8 |
+
When an intermediate file generated during the build is consumed
|
| 9 |
+
by an expensive operation or a large tree of dependents, one may
|
| 10 |
+
reduce the work needed for an incremental rebuild by updating the
|
| 11 |
+
file timestamp only when its content changes. With this approach
|
| 12 |
+
the generation rule must have a separate output file that is always
|
| 13 |
+
updated with a new timestamp that is newer than any dependencies of
|
| 14 |
+
the rule so that the build tool re-runs the rule only when the input
|
| 15 |
+
changes. We refer to the separate output file as a rule's *witness*
|
| 16 |
+
and the generated file as a rule's *byproduct*.
|
| 17 |
+
|
| 18 |
+
Byproducts may not be listed as outputs because their timestamps are
|
| 19 |
+
allowed to be older than the inputs. No build tools (like ``make``)
|
| 20 |
+
that existed when CMake was designed have a way to express byproducts.
|
| 21 |
+
Therefore CMake versions prior to 3.2 had no way to specify them.
|
| 22 |
+
Projects typically left byproducts undeclared in the rules that
|
| 23 |
+
generate them. For example:
|
| 24 |
+
|
| 25 |
+
.. code-block:: cmake
|
| 26 |
+
|
| 27 |
+
add_custom_command(
|
| 28 |
+
OUTPUT witness.txt
|
| 29 |
+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
| 30 |
+
${CMAKE_CURRENT_SOURCE_DIR}/input.txt
|
| 31 |
+
byproduct.txt # timestamp may not change
|
| 32 |
+
COMMAND ${CMAKE_COMMAND} -E touch witness.txt
|
| 33 |
+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/input.txt
|
| 34 |
+
)
|
| 35 |
+
add_custom_target(Provider DEPENDS witness.txt)
|
| 36 |
+
add_custom_command(
|
| 37 |
+
OUTPUT generated.c
|
| 38 |
+
COMMAND expensive-task -i byproduct.txt -o generated.c
|
| 39 |
+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/byproduct.txt
|
| 40 |
+
)
|
| 41 |
+
add_library(Consumer generated.c)
|
| 42 |
+
add_dependencies(Consumer Provider)
|
| 43 |
+
|
| 44 |
+
This works well for all generators except :generator:`Ninja`.
|
| 45 |
+
The Ninja build tool sees a rule listing ``byproduct.txt``
|
| 46 |
+
as a dependency and no rule listing it as an output. Ninja then
|
| 47 |
+
complains that there is no way to satisfy the dependency and
|
| 48 |
+
stops building even though there are order-only dependencies
|
| 49 |
+
that ensure ``byproduct.txt`` will exist before its consumers
|
| 50 |
+
need it. See discussion of this problem in `Ninja Issue 760`_
|
| 51 |
+
for further details on why Ninja works this way.
|
| 52 |
+
|
| 53 |
+
.. _Ninja Issue 760: https://github.com/ninja-build/ninja/issues/760
|
| 54 |
+
|
| 55 |
+
Instead of leaving byproducts undeclared in the rules that generate
|
| 56 |
+
them, Ninja expects byproducts to be listed along with other outputs.
|
| 57 |
+
Such rules may be marked with a ``restat`` option that tells Ninja
|
| 58 |
+
to check the timestamps of outputs after the rules run. This
|
| 59 |
+
prevents byproducts whose timestamps do not change from causing
|
| 60 |
+
their dependents to re-build unnecessarily.
|
| 61 |
+
|
| 62 |
+
Since the above approach does not tell CMake what custom command
|
| 63 |
+
generates ``byproduct.txt``, the Ninja generator does not have
|
| 64 |
+
enough information to add the byproduct as an output of any rule.
|
| 65 |
+
CMake 2.8.12 and above work around this problem and allow projects
|
| 66 |
+
using the above approach to build by generating ``phony`` build
|
| 67 |
+
rules to tell Ninja to tolerate such missing files. However, this
|
| 68 |
+
workaround prevents Ninja from diagnosing a dependency that is
|
| 69 |
+
really missing. It also works poorly in in-source builds where
|
| 70 |
+
every custom command dependency, even on source files, needs to
|
| 71 |
+
be treated this way because CMake does not have enough information
|
| 72 |
+
to know which files are generated as byproducts of custom commands.
|
| 73 |
+
|
| 74 |
+
Introducing Byproducts
|
| 75 |
+
^^^^^^^^^^^^^^^^^^^^^^
|
| 76 |
+
|
| 77 |
+
CMake 3.2 introduced the ``BYPRODUCTS`` option to the
|
| 78 |
+
:command:`add_custom_command` and :command:`add_custom_target`
|
| 79 |
+
commands. This option allows byproducts to be specified explicitly:
|
| 80 |
+
|
| 81 |
+
.. code-block:: cmake
|
| 82 |
+
|
| 83 |
+
add_custom_command(
|
| 84 |
+
OUTPUT witness.txt
|
| 85 |
+
BYPRODUCTS byproduct.txt # explicit byproduct specification
|
| 86 |
+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
| 87 |
+
${CMAKE_CURRENT_SOURCE_DIR}/input.txt
|
| 88 |
+
byproduct.txt # timestamp may not change
|
| 89 |
+
...
|
| 90 |
+
|
| 91 |
+
The ``BYPRODUCTS`` option is used by the :generator:`Ninja` generator
|
| 92 |
+
to list byproducts among the outputs of the custom commands that
|
| 93 |
+
generate them, and is ignored by other generators.
|
| 94 |
+
|
| 95 |
+
CMake 3.3 and above prefer to require projects to specify custom
|
| 96 |
+
command byproducts explicitly so that it can avoid using the
|
| 97 |
+
``phony`` rule workaround altogether. Policy ``CMP0058`` was
|
| 98 |
+
introduced to provide compatibility with existing projects that
|
| 99 |
+
still need the workaround.
|
| 100 |
+
|
| 101 |
+
This policy has no effect on generators other than :generator:`Ninja`.
|
| 102 |
+
The ``OLD`` behavior for this policy is to generate Ninja ``phony``
|
| 103 |
+
rules for unknown dependencies in the build tree. The ``NEW``
|
| 104 |
+
behavior for this policy is to not generate these and instead
|
| 105 |
+
require projects to specify custom command ``BYPRODUCTS`` explicitly.
|
| 106 |
+
|
| 107 |
+
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.3
|
| 108 |
+
.. |WARNS_OR_DOES_NOT_WARN| replace::
|
| 109 |
+
warns when it sees unknown dependencies in out-of-source build trees
|
| 110 |
+
.. include:: STANDARD_ADVICE.txt
|
| 111 |
+
|
| 112 |
+
The policy setting must be in scope at the end of the top-level
|
| 113 |
+
``CMakeLists.txt`` file of the project and has global effect.
|
| 114 |
+
|
| 115 |
+
.. include:: DEPRECATED.txt
|
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0081.rst
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMP0081
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.13
|
| 5 |
+
|
| 6 |
+
Relative paths not allowed in :prop_tgt:`LINK_DIRECTORIES` target property.
|
| 7 |
+
|
| 8 |
+
CMake 3.12 and lower allowed the :prop_dir:`LINK_DIRECTORIES` directory
|
| 9 |
+
property to contain relative paths. The base path for such relative
|
| 10 |
+
entries is not well defined. CMake 3.13 and later will issue a
|
| 11 |
+
``FATAL_ERROR`` if the :prop_tgt:`LINK_DIRECTORIES` target property
|
| 12 |
+
(which is initialized by the :prop_dir:`LINK_DIRECTORIES` directory property)
|
| 13 |
+
contains a relative path.
|
| 14 |
+
|
| 15 |
+
The ``OLD`` behavior for this policy is not to warn about relative paths
|
| 16 |
+
in the :prop_tgt:`LINK_DIRECTORIES` target property. The ``NEW`` behavior for
|
| 17 |
+
this policy is to issue a ``FATAL_ERROR`` if :prop_tgt:`LINK_DIRECTORIES`
|
| 18 |
+
contains a relative path.
|
| 19 |
+
|
| 20 |
+
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.13
|
| 21 |
+
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
| 22 |
+
.. include:: STANDARD_ADVICE.txt
|
| 23 |
+
|
| 24 |
+
.. include:: DEPRECATED.txt
|
openflamingo/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Help/policy/CMP0111.rst
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMP0111
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.19
|
| 5 |
+
|
| 6 |
+
An imported target missing its location property fails during generation.
|
| 7 |
+
|
| 8 |
+
:ref:`Imported Targets` for library files and executables require that
|
| 9 |
+
their location on disk is specified in a target property such as
|
| 10 |
+
:prop_tgt:`IMPORTED_LOCATION`, :prop_tgt:`IMPORTED_IMPLIB`, or a
|
| 11 |
+
per-configuration equivalent. If a needed location property is not set,
|
| 12 |
+
CMake 3.18 and below generate the string ``<TARGET_NAME>-NOTFOUND`` in
|
| 13 |
+
its place, which results in failures of the corresponding rules at build
|
| 14 |
+
time. CMake 3.19 and above prefer instead to raise an error during
|
| 15 |
+
generation. This policy provides compatibility for projects that have
|
| 16 |
+
not been updated to expect the new behavior.
|
| 17 |
+
|
| 18 |
+
The ``OLD`` behavior of this policy is to generate the location of an imported
|
| 19 |
+
unknown, static or shared library target as ``<TARGET_NAME>-NOTFOUND`` if not
|
| 20 |
+
set.
|
| 21 |
+
The ``NEW`` behavior is to raise an error.
|
| 22 |
+
|
| 23 |
+
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.19
|
| 24 |
+
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
| 25 |
+
.. include:: STANDARD_ADVICE.txt
|
| 26 |
+
|
| 27 |
+
.. include:: DEPRECATED.txt
|