commit: 7c70eea2f607baffcbb9d465c03578d69b09decf Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Wed Dec 3 08:44:40 2014 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Wed Dec 3 18:29:26 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7c70eea2
portage.os.waitpid: handle EINTR for bug #525552 Use a new _eintr_func_wrapper class to wrap waitpid calls and handle EINTR by calling the function as many times as necessary (until it returns without raising EINTR). X-Gentoo-Bug: 525552 X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=525552 Acked-by: Alexander Berntsen <bernalex <AT> gentoo.org> --- pym/portage/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index d8046f3..4ce92f5 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -320,12 +320,36 @@ class _unicode_module_wrapper(object): cache[attr] = result return result +class _eintr_func_wrapper(object): + """ + Wraps a function and handles EINTR by calling the function as + many times as necessary (until it returns without raising EINTR). + """ + + __slots__ = ('_func',) + + def __init__(self, func): + self._func = func + + def __call__(self, *args, **kwargs): + + while True: + try: + rval = self._func(*args, **kwargs) + break + except OSError as e: + if e.errno != errno.EINTR: + raise + + return rval + import os as _os _os_overrides = { id(_os.fdopen) : _os.fdopen, id(_os.popen) : _os.popen, id(_os.read) : _os.read, id(_os.system) : _os.system, + id(_os.waitpid) : _eintr_func_wrapper(_os.waitpid) }
