diff --git a/docs/index.rst b/docs/index.rst index 4a2a5b941..9848b0680 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -681,12 +681,18 @@ Process class The process name. The return value is cached after first call. + *Changed in 3.2.0:* (Windows, Python 2) in case of non ASCII name the + returned type is unicode instead of str. + .. method:: exe() The process executable as an absolute path. On some systems this may also be an empty string. The return value is cached after first call. + *Changed in 3.2.0:* (Windows, Python 2) in case of non ASCII path the + returned type is unicode instead of str. + .. method:: cmdline() The command line this process has been called with. diff --git a/psutil/__init__.py b/psutil/__init__.py index 385b80a4a..166883620 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -158,7 +158,7 @@ ] __all__.extend(_psplatform.__extra__all__) __author__ = "Giampaolo Rodola'" -__version__ = "3.1.2" +__version__ = "3.2.0" version_info = tuple([int(num) for num in __version__.split('.')]) AF_LINK = _psplatform.AF_LINK _TOTAL_PHYMEM = None diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 2d8babb19..ca48120f0 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -234,6 +234,16 @@ def users(): return retlist +def py2_stringify(s): + if PY3: + return s + else: + try: + return str(s) + except UnicodeEncodeError: + return s + + pids = cext.pids pid_exists = cext.pid_exists net_io_counters = cext.net_io_counters @@ -287,9 +297,9 @@ def name(self): try: # Note: this will fail with AD for most PIDs owned # by another user but it's faster. - return os.path.basename(self.exe()) + return py2_stringify(os.path.basename(self.exe())) except AccessDenied: - return cext.proc_name(self.pid) + return py2_stringify(cext.proc_name(self.pid)) @wrap_exceptions def exe(self): @@ -301,7 +311,7 @@ def exe(self): # see https://github.com/giampaolo/psutil/issues/528 if self.pid in (0, 4): raise AccessDenied(self.pid, self._name) - return _convert_raw_path(cext.proc_exe(self.pid)) + return py2_stringify(_convert_raw_path(cext.proc_exe(self.pid))) @wrap_exceptions def cmdline(self): diff --git a/test/_windows.py b/test/_windows.py index 93331789a..5d6fd366f 100644 --- a/test/_windows.py +++ b/test/_windows.py @@ -292,7 +292,7 @@ def test_name_always_available(self): for p in psutil.process_iter(): try: p.name() - except psutil.NoSuchProcess(): + except psutil.NoSuchProcess: pass