summaryrefslogtreecommitdiff
path: root/psutil/_compat.py
Commit message (Collapse)AuthorAgeFilesLines
* Fix pylint warnings / cleanup (#2218)Giampaolo Rodola2023-04-011-2/+2
|
* introduce flake8-bugbear code checkerGiampaolo Rodola2022-05-251-5/+5
| | | | Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* Automatically sort imports (isort CLI tool) (#2033)Giampaolo Rodola2021-12-141-1/+2
|
* Changes to debug() function:Giampaolo Rodola2021-10-141-0/+17
| | | | | | | | | | * use str() if exception derives from OSError / EnvironmentError. This way we will print the file name (if it exists). * use repr() for any other exception * add tests for debug() function * backport contextlib.redirect_stderr Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
* Linux: wait_procs ignoring timeout (#1913) (#1917)Guillermo2021-02-181-0/+8
| | | | | | | The function was exiting after one second due to a subprocess.TimeoutException Fixes #1913 Signed-off-by: guille <guille@users.noreply.github.com>
* Memory leak test: take fluctuations into account (#1757)Giampaolo Rodola2020-05-131-16/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Preamble ======= We have a [memory leak test suite](https://github.com/giampaolo/psutil/blob/e1ea2bccf8aea404dca0f79398f36f37217c45f6/psutil/tests/__init__.py#L897), which calls a function many times and fails if the process memory increased. We do this in order to detect missing `free()` or `Py_DECREF` calls in the C modules. When we do, then we have a memory leak. The problem ========== A problem we've been having for probably over 10 years, is the false positives. That's because the memory fluctuates. Sometimes it may increase (or even decrease!) due to how the OS handles memory, the Python's garbage collector, the fact that RSS is an approximation and who knows what else. So thus far we tried to compensate that by using the following logic: - warmup (call fun 10 times) - call the function many times (1000) - if memory increased before/after calling function 1000 times, then keep calling it for another 3 secs - if it still increased at all (> 0) then fail This logic didn't really solve the problem, as we still had occasional false positives, especially lately on FreeBSD. The solution ========= This PR changes the internal algorithm so that in case of failure (mem > 0 after calling fun() N times) we retry the test for up to 5 times, increasing N (repetitions) each time, so we consider it a failure only if the memory **keeps increasing** between runs. So for instance, here's a legitimate failure: ``` psutil.tests.test_memory_leaks.TestModuleFunctionsLeaks.test_disk_partitions ... Run #1: extra-mem=696.0K, per-call=3.5K, calls=200 Run #2: extra-mem=1.4M, per-call=3.5K, calls=400 Run #3: extra-mem=2.1M, per-call=3.5K, calls=600 Run #4: extra-mem=2.7M, per-call=3.5K, calls=800 Run #5: extra-mem=3.4M, per-call=3.5K, calls=1000 FAIL ``` If, on the other hand, the memory increased on one run (say 200 calls) but decreased on the next run (say 400 calls), then it clearly means it's a false positive, because memory consumption may be > 0 on second run, but if it's lower than the previous run with less repetitions, then it cannot possibly represent a leak (just a fluctuation): ``` psutil.tests.test_memory_leaks.TestModuleFunctionsLeaks.test_net_connections ... Run #1: extra-mem=568.0K, per-call=2.8K, calls=200 Run #2: extra-mem=24.0K, per-call=61.4B, calls=400 OK ``` Note about mallinfo() ================ Aka #1275. `mallinfo()` on Linux is supposed to provide memory metrics about how many bytes gets allocated on the heap by `malloc()`, so it's supposed to be way more precise than RSS and also [USS](http://grodola.blogspot.com/2016/02/psutil-4-real-process-memory-and-environ.html). In another branch were I exposed it, I verified that fluctuations still occur even when using `mallinfo()` though, despite less often. So that means even `mallinfo()` would not grant 100% stability.
* Backport python 3 super() (#1733)Giampaolo Rodola2020-04-241-21/+100
|
* MemoryLeakTest class enhancements (#1731)Giampaolo Rodola2020-04-231-1/+16
|
* Git hook for renamed/added/deleted files + flake8 print() + tidelift (#1704)Giampaolo Rodola2020-02-211-1/+1
|
* #1659: provide error message in case of bugged PYPY2 versionGiampaolo Rodola2020-02-141-0/+12
|
* small refactoringGiampaolo Rodola2020-02-141-6/+7
|
* PEP-3151: backport FS exceptions to Python 2 (#1544)Giampaolo Rodola2019-06-281-1/+71
|
* move get_terminal_size() in _compat.pyGiampaolo Rodola2019-04-051-1/+22
|
* Remove additional workarounds and support for Python 3.2 & 3.3 (#1228)Jon Dufresne2018-03-041-9/+1
| | | | | | Support for Python 3.3 was dropped in version 5.4.1. Support for Python 3.2 was dropped earlier. Remove all references to these unsupported versions including documentation, scripts, workarounds, etc. Eases maintenance as fewer workarounds are used for unsupported environments.
* 1058 enable fix warnings (#1059)Giampaolo Rodola2017-05-101-49/+1
| | | | | | | | | | | | | | | | | | * #1058: have Makefile use PYTHONWARNINGS=all by default for (almost) all commands * #1058 fix linux tests warnings * #1058: try not to use imp module * #1058: get rid of imp module completely * #1058: ignore unicode warnings * #1058: ignore stderr from procsmem.py * #1058: fix resource warning from Popen * #1058: get rid of contextlib.nested (deprecated)
* filter shared libs with looking for 'python' in their nameGiampaolo Rodola2017-05-071-2/+1
|
* fix python bug of socket.setblocking() which changes socket.type value - ↵Giampaolo Rodola2017-04-291-1/+1
| | | | http://bugs.python.org/issue30204
* add a test case which exposes #1013 on FreeBSDGiampaolo Rodola2017-04-291-0/+49
|
* update __all__Giampaolo Rodola2016-06-041-1/+2
|
* #717: ignore everything after the first occurrence of '\x00' instead of ↵Giampaolo Rodola2015-12-151-0/+2
| | | | replacing '\x00' for the whole string
* openbsd: fix some tests + memory leak in swap_mem()Giampaolo Rodola2015-11-241-2/+2
|
* merge from masterGiampaolo Rodola2015-11-061-0/+6
|\
| * #558: [Linux] expose psutil.PROCFS_PATH constantGiampaolo Rodola2015-10-311-0/+6
| |
* | Fallback on using which(cmdline()[0]) since exe() does not exist onGiampaolo Rodola2015-09-071-0/+53
|/ | | | OpenBSD
* Merge pull request #573 from tomprince/remove-shebang-linesEvinceMoi-fix-net_io_counter-overflowGiampaolo Rodola'2015-09-031-2/+0
|\ | | | | Modules aren't scripts.
| * Modules aren't scripts.Tom Prince2015-01-081-2/+0
| | | | | | | | They shouldn't have shebang lines.
* | #639: add testGiampaolo Rodola2015-07-111-0/+6
| |
* | fix flake8 complaintsGiampaolo Rodola2015-02-071-2/+2
| |
* | remove unused importGiampaolo Rodola2015-02-061-4/+0
| |
* | remove names which are no longer in use from _compat.pyGiampaolo Rodola2015-02-061-17/+1
|/
* #521 remove python 2.4 and 2.5 supportGiampaolo Rodola2014-11-011-239/+7
|
* github migrationGiampaolo Rodola'2014-05-231-0/+2
|
* fix issue 478 (Linux): open /proc files in binary mode on Python 3.4: this ↵Giampaolo Rodola'2014-02-161-0/+6
| | | | results in a considerable speedup (from ~ 30% to 50%)
* update CREDITSGiampaolo Rodola'2013-12-141-0/+4
|
* pep8ify line > 80 charsGiampaolo Rodola'2013-12-081-7/+8
|
* refactoring of _compat.pyGiampaolo Rodola'2013-12-081-34/+14
|
* introduce @lru_cache decorator from python 3.2Giampaolo Rodola'2013-12-081-0/+168
|
* pep8ifyGiampaolo Rodola'2013-11-261-7/+9
|
* pep8ifyGiampaolo Rodola'2013-11-211-16/+15
|
* _compat.callable: synchronize it with the version defined into six libraryGiampaolo Rodola'2013-10-261-5/+2
|
* pylintGiampaolo Rodola'2013-10-031-1/+1
|
* Fix issue 416 (Linux): try to encode() the path name in case statvfs() raise ↵Giampaolo Rodola'2013-08-091-0/+8
| | | | UnicodeEncodeError and then retry; also add unit tests for unicode path names passed to disk_usage()
* update psutil project ownershipGiampaolo Rodola'2013-06-081-1/+1
|
* Remove "$Id$" occurrences from source code files. They were used by svn ↵Giampaolo Rodola'2013-03-261-3/+1
| | | | propset functionnality which no longer applies now that we're using Mercurial.
* Fix issue 318: reintroduce python 2.4 compatibility which was accidentally ↵Giampaolo Rodola'2012-08-161-0/+24
| | | | broken in 0.6.0 release (patch by Riccardo Murri)
* add 'print_' function as 2/3 compatibility layerGiampaolo Rodola'2012-06-091-0/+6
|
* fix issue #274: rewrite code in an idiom which works with both python 2.x ↵Giampaolo Rodola'2012-06-031-8/+56
| | | | and 3.x avoiding the 2to3 run at installation time
* add who.py example scriptGiampaolo Rodola'2012-04-161-1/+1
|
* #242: change the recursive algorithm to get process children: use a ↵Giampaolo Rodola'2012-04-081-1/+52
| | | | defaultdict to construct a table where 'values' are all the processes having 'keys' as their parent and then recursively iterate over it. This is an order of magnitude faster
* update compatibilty hack for property setters/deleters (py < 2.6) with a ↵Giampaolo Rodola'2011-10-111-27/+14
| | | | cleaner and more efficient version