psutil.tests.test_memory_leaks

Tests for detecting function memory leaks (typically the ones implemented in C). It does so by calling a function many times and checking whether process memory usage keeps increasing between calls or over time. Note that this may produce false positives (especially on Windows for some reason).

Module Contents

LOOPS = 1000
MEMORY_TOLERANCE = 4096
RETRY_FOR = 3
SKIP_PYTHON_IMPL
cext
thisproc
SKIP_PYTHON_IMPL
skip_if_linux()
bytes2human(n)

http://code.activestate.com/recipes/578019 >>> bytes2human(10000) ‘9.8K’ >>> bytes2human(100001221) ‘95.4M’

class TestMemLeak

Bases:psutil.tests.unittest.TestCase

Base framework class which calls a function many times and produces a failure if process memory usage keeps increasing between calls or over time.

tolerance
loops
retry_for
setUp(self)
execute(self, fun, *args, **kwargs)

Test a callable.

execute_w_exc(self, exc, fun, *args, **kwargs)

Convenience function which tests a callable raising an exception.

static _get_mem()
static _call(fun, *args, **kwargs)
class TestProcessObjectLeaks

Bases:psutil.tests.test_memory_leaks.TestMemLeak

Test leaks of Process class methods.

proc
test_coverage(self)
test_name(self)
test_cmdline(self)
test_exe(self)
test_ppid(self)
test_uids(self)
test_gids(self)
test_status(self)
test_nice_get(self)
test_nice_set(self)
test_ionice_get(self)
test_ionice_set(self)
test_io_counters(self)
test_username(self)
test_create_time(self)
test_num_threads(self)
test_num_handles(self)
test_num_fds(self)
test_num_ctx_switches(self)
test_threads(self)
test_cpu_times(self)
test_cpu_num(self)
test_memory_info(self)
test_memory_full_info(self)
test_terminal(self)
test_resume(self)
test_cwd(self)
test_cpu_affinity_get(self)
test_cpu_affinity_set(self)
test_open_files(self)
test_memory_maps(self)
test_rlimit_get(self)
test_rlimit_set(self)
test_connections(self)
test_environ(self)
test_proc_info(self)
class TestProcessDualImplementation

Bases:psutil.tests.test_memory_leaks.TestMemLeak

test_cmdline_peb_true(self)
class TestTerminatedProcessLeaks

Bases:psutil.tests.test_memory_leaks.TestProcessObjectLeaks

Repeat the tests above looking for leaks occurring when dealing with terminated processes raising NoSuchProcess exception. The C functions are still invoked but will follow different code paths. We’ll check those code paths.

classmethod setUpClass(cls)
classmethod tearDownClass(cls)
_call(self, fun, *args, **kwargs)
test_kill(self)
class TestModuleFunctionsLeaks

Bases:psutil.tests.test_memory_leaks.TestMemLeak

Test leaks of psutil module functions.

test_coverage(self)
test_cpu_count_logical(self)
test_cpu_count_physical(self)
test_cpu_times(self)
test_per_cpu_times(self)
test_cpu_stats(self)
test_cpu_freq(self)
test_virtual_memory(self)
test_swap_memory(self)
test_pid_exists(self)
test_disk_usage(self)
test_disk_partitions(self)
test_disk_io_counters(self)
test_pids(self)
test_net_io_counters(self)
test_net_connections(self)
test_net_if_addrs(self)
test_net_if_stats(self)
test_sensors_battery(self)
test_sensors_temperatures(self)
test_sensors_fans(self)
test_boot_time(self)
test_users(self)
test_win_service_iter(self)