Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/
Date: Wed, 03 Dec 2014 18:30:10
Message-Id: 1417631366.7c70eea2f607baffcbb9d465c03578d69b09decf.zmedico@gentoo
1 commit: 7c70eea2f607baffcbb9d465c03578d69b09decf
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Wed Dec 3 08:44:40 2014 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Wed Dec 3 18:29:26 2014 +0000
6 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7c70eea2
7
8 portage.os.waitpid: handle EINTR for bug #525552
9
10 Use a new _eintr_func_wrapper class to wrap waitpid calls and handle
11 EINTR by calling the function as many times as necessary (until it
12 returns without raising EINTR).
13
14 X-Gentoo-Bug: 525552
15 X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=525552
16 Acked-by: Alexander Berntsen <bernalex <AT> gentoo.org>
17
18 ---
19 pym/portage/__init__.py | 24 ++++++++++++++++++++++++
20 1 file changed, 24 insertions(+)
21
22 diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
23 index d8046f3..4ce92f5 100644
24 --- a/pym/portage/__init__.py
25 +++ b/pym/portage/__init__.py
26 @@ -320,12 +320,36 @@ class _unicode_module_wrapper(object):
27 cache[attr] = result
28 return result
29
30 +class _eintr_func_wrapper(object):
31 + """
32 + Wraps a function and handles EINTR by calling the function as
33 + many times as necessary (until it returns without raising EINTR).
34 + """
35 +
36 + __slots__ = ('_func',)
37 +
38 + def __init__(self, func):
39 + self._func = func
40 +
41 + def __call__(self, *args, **kwargs):
42 +
43 + while True:
44 + try:
45 + rval = self._func(*args, **kwargs)
46 + break
47 + except OSError as e:
48 + if e.errno != errno.EINTR:
49 + raise
50 +
51 + return rval
52 +
53 import os as _os
54 _os_overrides = {
55 id(_os.fdopen) : _os.fdopen,
56 id(_os.popen) : _os.popen,
57 id(_os.read) : _os.read,
58 id(_os.system) : _os.system,
59 + id(_os.waitpid) : _eintr_func_wrapper(_os.waitpid)
60 }