1 |
Use a new _eintr_func_wrapper class to wrap waitpid calls and handle |
2 |
EINTR by calling the function as many times as necessary (until it |
3 |
returns without raising EINTR). |
4 |
|
5 |
X-Gentoo-Bug: 525552 |
6 |
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=525552 |
7 |
--- |
8 |
pym/portage/__init__.py | 24 ++++++++++++++++++++++++ |
9 |
1 file changed, 24 insertions(+) |
10 |
|
11 |
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py |
12 |
index d8046f3..4ce92f5 100644 |
13 |
--- a/pym/portage/__init__.py |
14 |
+++ b/pym/portage/__init__.py |
15 |
@@ -320,12 +320,36 @@ class _unicode_module_wrapper(object): |
16 |
cache[attr] = result |
17 |
return result |
18 |
|
19 |
+class _eintr_func_wrapper(object): |
20 |
+ """ |
21 |
+ Wraps a function and handles EINTR by calling the function as |
22 |
+ many times as necessary (until it returns without raising EINTR). |
23 |
+ """ |
24 |
+ |
25 |
+ __slots__ = ('_func',) |
26 |
+ |
27 |
+ def __init__(self, func): |
28 |
+ self._func = func |
29 |
+ |
30 |
+ def __call__(self, *args, **kwargs): |
31 |
+ |
32 |
+ while True: |
33 |
+ try: |
34 |
+ rval = self._func(*args, **kwargs) |
35 |
+ break |
36 |
+ except OSError as e: |
37 |
+ if e.errno != errno.EINTR: |
38 |
+ raise |
39 |
+ |
40 |
+ return rval |
41 |
+ |
42 |
import os as _os |
43 |
_os_overrides = { |
44 |
id(_os.fdopen) : _os.fdopen, |
45 |
id(_os.popen) : _os.popen, |
46 |
id(_os.read) : _os.read, |
47 |
id(_os.system) : _os.system, |
48 |
+ id(_os.waitpid) : _eintr_func_wrapper(_os.waitpid) |
49 |
} |
50 |
|
51 |
|
52 |
-- |
53 |
2.0.4 |