Skip to content

Commit

Permalink
#650: stringify name and exe
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Aug 26, 2015
1 parent e907b34 commit 8d946e0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion test/_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 8d946e0

Please sign in to comment.