summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-02-07 05:23:27 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2015-02-07 05:23:27 +0100
commit2c81d1e838ee63e89de411c2d908d06e6058ba8f (patch)
treed2232bafb26095d9add7f7d4e5c9fca18fb84f07
parent97ecaf5877ea6d2599225ab2a76675b8b9edbfc9 (diff)
downloadpsutil-2c81d1e838ee63e89de411c2d908d06e6058ba8f.tar.gz
fix flake8 complaints
-rwxr-xr-xexamples/iotop.py13
-rwxr-xr-xexamples/nettop.py10
-rwxr-xr-xexamples/top.py11
-rw-r--r--psutil/__init__.py60
-rw-r--r--psutil/_compat.py4
-rw-r--r--psutil/_psposix.py6
-rw-r--r--psutil/_pswindows.py3
-rw-r--r--test/test_memory_leaks.py10
-rw-r--r--test/test_psutil.py11
9 files changed, 66 insertions, 62 deletions
diff --git a/examples/iotop.py b/examples/iotop.py
index a0986782..be3819b8 100755
--- a/examples/iotop.py
+++ b/examples/iotop.py
@@ -30,14 +30,15 @@ PID USER DISK READ DISK WRITE COMMAND
Author: Giampaolo Rodola' <g.rodola@gmail.com>
"""
-import os
+import atexit
+import time
import sys
-import psutil
-if not hasattr(psutil.Process, 'io_counters') or os.name != 'posix':
+try:
+ import curses
+except ImportError:
sys.exit('platform not supported')
-import time
-import curses
-import atexit
+
+import psutil
# --- curses stuff
diff --git a/examples/nettop.py b/examples/nettop.py
index 857285cf..7a8343ee 100755
--- a/examples/nettop.py
+++ b/examples/nettop.py
@@ -31,13 +31,13 @@ pkts-sent 0 0
pkts-recv 1214470 0
"""
-import sys
-import os
-if os.name != 'posix':
- sys.exit('platform not supported')
import atexit
-import curses
import time
+import sys
+try:
+ import curses
+except ImportError:
+ sys.exit('platform not supported')
import psutil
diff --git a/examples/top.py b/examples/top.py
index a305297f..7aebef1d 100755
--- a/examples/top.py
+++ b/examples/top.py
@@ -34,14 +34,15 @@ PID USER NI VIRT RES CPU% MEM% TIME+ NAME
...
"""
+from datetime import datetime, timedelta
+import atexit
import os
+import time
import sys
-if os.name != 'posix':
+try:
+ import curses
+except ImportError:
sys.exit('platform not supported')
-import atexit
-import curses
-import time
-from datetime import datetime, timedelta
import psutil
diff --git a/psutil/__init__.py b/psutil/__init__.py
index c985b10c..6b797c76 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -11,33 +11,6 @@ in Python.
"""
from __future__ import division
-
-__author__ = "Giampaolo Rodola'"
-__version__ = "3.0.0"
-version_info = tuple([int(num) for num in __version__.split('.')])
-
-__all__ = [
- # exceptions
- "Error", "NoSuchProcess", "AccessDenied", "TimeoutExpired",
- # constants
- "version_info", "__version__",
- "STATUS_RUNNING", "STATUS_IDLE", "STATUS_SLEEPING", "STATUS_DISK_SLEEP",
- "STATUS_STOPPED", "STATUS_TRACING_STOP", "STATUS_ZOMBIE", "STATUS_DEAD",
- "STATUS_WAKING", "STATUS_LOCKED", "STATUS_WAITING", "STATUS_LOCKED",
- "CONN_ESTABLISHED", "CONN_SYN_SENT", "CONN_SYN_RECV", "CONN_FIN_WAIT1",
- "CONN_FIN_WAIT2", "CONN_TIME_WAIT", "CONN_CLOSE", "CONN_CLOSE_WAIT",
- "CONN_LAST_ACK", "CONN_LISTEN", "CONN_CLOSING", "CONN_NONE",
- # classes
- "Process", "Popen",
- # functions
- "pid_exists", "pids", "process_iter", "wait_procs", # proc
- "virtual_memory", "swap_memory", # memory
- "cpu_times", "cpu_percent", "cpu_times_percent", "cpu_count", # cpu
- "net_io_counters", "net_connections", # network
- "disk_io_counters", "disk_partitions", "disk_usage", # disk
- "users", "boot_time", # others
-]
-
import collections
import errno
import functools
@@ -159,9 +132,32 @@ elif sys.platform.startswith("sunos"):
else:
raise NotImplementedError('platform %s is not supported' % sys.platform)
-__all__.extend(_psplatform.__extra__all__)
-
+__all__ = [
+ # exceptions
+ "Error", "NoSuchProcess", "AccessDenied", "TimeoutExpired",
+ # constants
+ "version_info", "__version__",
+ "STATUS_RUNNING", "STATUS_IDLE", "STATUS_SLEEPING", "STATUS_DISK_SLEEP",
+ "STATUS_STOPPED", "STATUS_TRACING_STOP", "STATUS_ZOMBIE", "STATUS_DEAD",
+ "STATUS_WAKING", "STATUS_LOCKED", "STATUS_WAITING", "STATUS_LOCKED",
+ "CONN_ESTABLISHED", "CONN_SYN_SENT", "CONN_SYN_RECV", "CONN_FIN_WAIT1",
+ "CONN_FIN_WAIT2", "CONN_TIME_WAIT", "CONN_CLOSE", "CONN_CLOSE_WAIT",
+ "CONN_LAST_ACK", "CONN_LISTEN", "CONN_CLOSING", "CONN_NONE",
+ # classes
+ "Process", "Popen",
+ # functions
+ "pid_exists", "pids", "process_iter", "wait_procs", # proc
+ "virtual_memory", "swap_memory", # memory
+ "cpu_times", "cpu_percent", "cpu_times_percent", "cpu_count", # cpu
+ "net_io_counters", "net_connections", # network
+ "disk_io_counters", "disk_partitions", "disk_usage", # disk
+ "users", "boot_time", # others
+]
+__all__.extend(_psplatform.__extra__all__)
+__author__ = "Giampaolo Rodola'"
+__version__ = "3.0.0"
+version_info = tuple([int(num) for num in __version__.split('.')])
_TOTAL_PHYMEM = None
_POSIX = os.name == 'posix'
_WINDOWS = os.name == 'nt'
@@ -851,9 +847,11 @@ class Process(object):
blocking = interval is not None and interval > 0.0
num_cpus = cpu_count()
if _POSIX:
- timer = lambda: _timer() * num_cpus
+ def timer():
+ return _timer() * num_cpus
else:
- timer = lambda: sum(cpu_times())
+ def timer():
+ return sum(cpu_times())
if blocking:
st1 = timer()
pt1 = self._proc.cpu_times()
diff --git a/psutil/_compat.py b/psutil/_compat.py
index b52a04f0..dbb8dc1c 100644
--- a/psutil/_compat.py
+++ b/psutil/_compat.py
@@ -6,12 +6,12 @@
"""Module which provides compatibility with older Python versions."""
-__all__ = ["PY3", "long", "xrange", "unicode", "callable", "lru_cache"]
-
import collections
import functools
import sys
+__all__ = ["PY3", "long", "xrange", "unicode", "callable", "lru_cache"]
+
PY3 = sys.version_info[0] == 3
if PY3:
diff --git a/psutil/_psposix.py b/psutil/_psposix.py
index 94db351e..1f7dc96e 100644
--- a/psutil/_psposix.py
+++ b/psutil/_psposix.py
@@ -68,10 +68,12 @@ def wait_pid(pid, timeout=None):
timer = getattr(time, 'monotonic', time.time)
if timeout is not None:
- waitcall = lambda: os.waitpid(pid, os.WNOHANG)
+ def waitcall():
+ return os.waitpid(pid, os.WNOHANG)
stop_at = timer() + timeout
else:
- waitcall = lambda: os.waitpid(pid, 0)
+ def waitcall():
+ return os.waitpid(pid, 0)
delay = 0.0001
while True:
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index b1f2a45d..847f2b62 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -447,7 +447,8 @@ class Process(object):
@wrap_exceptions
def cpu_affinity_get(self):
- from_bitmask = lambda x: [i for i in xrange(64) if (1 << i) & x]
+ def from_bitmask(x):
+ return [i for i in xrange(64) if (1 << i) & x]
bitmask = cext.proc_cpu_affinity_get(self.pid)
return from_bitmask(bitmask)
diff --git a/test/test_memory_leaks.py b/test/test_memory_leaks.py
index be346269..827f9d47 100644
--- a/test/test_memory_leaks.py
+++ b/test/test_memory_leaks.py
@@ -17,11 +17,6 @@ import sys
import threading
import time
-if sys.version_info < (2, 7):
- import unittest2 as unittest # https://pypi.python.org/pypi/unittest2
-else:
- import unittest
-
import psutil
import psutil._common
@@ -31,6 +26,11 @@ from test_psutil import (WINDOWS, POSIX, OSX, LINUX, SUNOS, BSD, TESTFN,
from test_psutil import (reap_children, supports_ipv6, safe_remove,
get_test_subprocess)
+if sys.version_info < (2, 7):
+ import unittest2 as unittest # https://pypi.python.org/pypi/unittest2
+else:
+ import unittest
+
LOOPS = 1000
TOLERANCE = 4096
diff --git a/test/test_psutil.py b/test/test_psutil.py
index 9442b88c..8bdb0b9c 100644
--- a/test/test_psutil.py
+++ b/test/test_psutil.py
@@ -51,14 +51,14 @@ try:
except ImportError:
enum = None
+import psutil
+from psutil._compat import PY3, callable, long, unicode
+
if sys.version_info < (2, 7):
import unittest2 as unittest # https://pypi.python.org/pypi/unittest2
else:
import unittest
-import psutil
-from psutil._compat import PY3, callable, long, unicode
-
# ===================================================================
# --- Constants
@@ -546,9 +546,10 @@ class TestSystemAPIs(unittest.TestCase):
self.assertEqual(len(list(psutil.process_iter())), len(psutil.pids()))
def test_wait_procs(self):
- l = []
- callback = lambda p: l.append(p.pid)
+ def callback(p):
+ l.append(p.pid)
+ l = []
sproc1 = get_test_subprocess()
sproc2 = get_test_subprocess()
sproc3 = get_test_subprocess()