Skip to content

Commit

Permalink
Retry WindowsError ERROR_PARTIAL_COPY
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbarczynski committed Feb 12, 2019
1 parent 314ab75 commit caba750
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,24 @@ def wrapper(self, *args, **kwargs):
return wrapper


def retry_error_partial_copy(fun):
"""
Workaround for https://github.com/giampaolo/psutil/issues/875#issuecomment-298758923
"""

@functools.wraps(fun)
def wrapper(self, *args, **kwargs):
for idx in range(5):
try:
return fun(self, *args, **kwargs)
except WindowsError as err:
ERROR_PARTIAL_COPY = 299
if idx < 4 and err.winerror == ERROR_PARTIAL_COPY:
continue
raise
return wrapper


class Process(object):
"""Wrapper class around underlying C implementation."""

Expand Down Expand Up @@ -701,6 +719,7 @@ def exe(self):
return py2_strencode(convert_dos_path(cext.proc_exe(self.pid)))

@wrap_exceptions
@retry_error_partial_copy
def cmdline(self):
ret = cext.proc_cmdline(self.pid)
if PY3:
Expand All @@ -709,6 +728,7 @@ def cmdline(self):
return [py2_strencode(s) for s in ret]

@wrap_exceptions
@retry_error_partial_copy
def environ(self):
ustr = cext.proc_environ(self.pid)
if ustr and not PY3:
Expand Down Expand Up @@ -885,6 +905,7 @@ def resume(self):
return cext.proc_resume(self.pid)

@wrap_exceptions
@retry_error_partial_copy
def cwd(self):
if self.pid in (0, 4):
raise AccessDenied(self.pid, self._name)
Expand Down

0 comments on commit caba750

Please sign in to comment.