summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-05-05 20:17:02 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2020-05-05 20:17:02 +0200
commitba2047b0e4c018fa3eea004456ffb9bca046a5bd (patch)
tree51e90f1d5e2777e145b20295b9b8d5f36a9a340a
parentdbd8dd6b902641a3a6ee69ccc72fa556eee16273 (diff)
parent8ad353bc515d7765e7dc3dfaaa8f9f6db4f85aba (diff)
downloadpsutil-ba2047b0e4c018fa3eea004456ffb9bca046a5bd.tar.gz
Merge branch 'master' of github.com:giampaolo/psutil
-rw-r--r--psutil/arch/windows/net.c2
-rwxr-xr-xpsutil/tests/test_memory_leaks.py22
-rwxr-xr-xsetup.py4
3 files changed, 24 insertions, 4 deletions
diff --git a/psutil/arch/windows/net.c b/psutil/arch/windows/net.c
index 56c6b6f1..0891bdba 100644
--- a/psutil/arch/windows/net.c
+++ b/psutil/arch/windows/net.c
@@ -17,6 +17,8 @@
static PIP_ADAPTER_ADDRESSES
psutil_get_nic_addresses() {
+ // Note: GetAdaptersAddresses() increase the handle count on first
+ // call (and not anymore later on).
// allocate a 15 KB buffer to start with
int outBufLen = 15000;
DWORD dwRetVal = 0;
diff --git a/psutil/tests/test_memory_leaks.py b/psutil/tests/test_memory_leaks.py
index b6845ac8..9131e442 100755
--- a/psutil/tests/test_memory_leaks.py
+++ b/psutil/tests/test_memory_leaks.py
@@ -136,6 +136,8 @@ class TestProcessObjectLeaks(TestMemoryLeak):
@unittest.skipIf(POSIX, "worthless on POSIX")
def test_username(self):
+ # always open 1 handle on Windows (only once)
+ psutil.Process().username()
self.execute(self.proc.username)
@skip_if_linux()
@@ -248,7 +250,7 @@ class TestProcessObjectLeaks(TestMemoryLeak):
@unittest.skipIf(not WINDOWS, "WINDOWS only")
def test_proc_info(self):
- self.execute(cext.proc_info, os.getpid())
+ self.execute(lambda: cext.proc_info(os.getpid()))
class TestTerminatedProcessLeaks(TestProcessObjectLeaks):
@@ -356,6 +358,7 @@ class TestModuleFunctionsLeaks(TestMemoryLeak):
@unittest.skipIf(not WINDOWS, "WINDOWS only")
def test_getloadavg(self):
+ psutil.getloadavg()
self.execute(psutil.getloadavg)
# --- mem
@@ -397,26 +400,41 @@ class TestModuleFunctionsLeaks(TestMemoryLeak):
# --- net
+ # XXX
@unittest.skipIf(TRAVIS and MACOS, "false positive on TRAVIS + MACOS")
@unittest.skipIf(CIRRUS and FREEBSD, "false positive on CIRRUS + FREEBSD")
@skip_if_linux()
@unittest.skipIf(not HAS_NET_IO_COUNTERS, 'not supported')
def test_net_io_counters(self):
+ if WINDOWS:
+ # GetAdaptersAddresses() increases the handle count on first
+ # call (only).
+ psutil.net_io_counters()
self.execute(lambda: psutil.net_io_counters(nowrap=False))
@skip_if_linux()
@unittest.skipIf(MACOS and os.getuid() != 0, "need root access")
def test_net_connections(self):
+ # always opens and handle on Windows() (once)
+ psutil.net_connections(kind='all')
with create_sockets():
- self.execute(psutil.net_connections, times=100)
+ self.execute(lambda: psutil.net_connections(kind='all'), times=100)
def test_net_if_addrs(self):
+ if WINDOWS:
+ # GetAdaptersAddresses() increases the handle count on first
+ # call (only).
+ psutil.net_if_addrs()
# Note: verified that on Windows this was a false positive.
self.execute(psutil.net_if_addrs,
tolerance=80 * 1024 if WINDOWS else 4096)
@unittest.skipIf(TRAVIS, "EPERM on travis")
def test_net_if_stats(self):
+ if WINDOWS:
+ # GetAdaptersAddresses() increases the handle count on first
+ # call (only).
+ psutil.net_if_stats()
self.execute(psutil.net_if_stats)
# --- sensors
diff --git a/setup.py b/setup.py
index fdaf4702..19153bda 100755
--- a/setup.py
+++ b/setup.py
@@ -402,7 +402,7 @@ def main():
missdeps("sudo yum install gcc python%s-devel" % py3)
elif MACOS:
print(hilite("XCode (https://developer.apple.com/xcode/) "
- "is not installed"), ok=False, file=sys.stderr)
+ "is not installed"), color="red", file=sys.stderr)
elif FREEBSD:
missdeps("pkg install gcc python%s" % py3)
elif OPENBSD:
@@ -419,7 +419,7 @@ def main():
ur = "http://www.microsoft.com/en-us/download/"
ur += "details.aspx?id=44266"
s = "VisualStudio is not installed; get it from %s" % ur
- print(hilite(s, ok=False), file=sys.stderr)
+ print(hilite(s, color="red"), file=sys.stderr)
if __name__ == '__main__':