1 |
commit: 58d15b3761571653d84cd3a617f22a338290e0e4 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Oct 3 10:00:23 2012 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Oct 3 10:00:23 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=58d15b37 |
7 |
|
8 |
EbuildFetcher/MergeProcess: inherit ForkProcess |
9 |
|
10 |
Also add missing __slots__ to ForkProcess. TODO: Share code |
11 |
between ForkProcess and MergeProcess. |
12 |
|
13 |
--- |
14 |
pym/_emerge/EbuildFetcher.py | 53 ++++++------------------------- |
15 |
pym/portage/dbapi/_MergeProcess.py | 6 ++-- |
16 |
pym/portage/util/_async/ForkProcess.py | 2 + |
17 |
3 files changed, 16 insertions(+), 45 deletions(-) |
18 |
|
19 |
diff --git a/pym/_emerge/EbuildFetcher.py b/pym/_emerge/EbuildFetcher.py |
20 |
index 2d9635a..3cbe1b8 100644 |
21 |
--- a/pym/_emerge/EbuildFetcher.py |
22 |
+++ b/pym/_emerge/EbuildFetcher.py |
23 |
@@ -1,13 +1,10 @@ |
24 |
# Copyright 1999-2012 Gentoo Foundation |
25 |
# Distributed under the terms of the GNU General Public License v2 |
26 |
|
27 |
-import traceback |
28 |
- |
29 |
-from _emerge.SpawnProcess import SpawnProcess |
30 |
import copy |
31 |
import io |
32 |
-import signal |
33 |
import sys |
34 |
+ |
35 |
import portage |
36 |
from portage import os |
37 |
from portage import _encodings |
38 |
@@ -16,9 +13,10 @@ from portage import _unicode_decode |
39 |
from portage.checksum import _hash_filter |
40 |
from portage.elog.messages import eerror |
41 |
from portage.package.ebuild.fetch import _check_distfile, fetch |
42 |
+from portage.util._async.ForkProcess import ForkProcess |
43 |
from portage.util._pty import _create_pty_or_pipe |
44 |
|
45 |
-class EbuildFetcher(SpawnProcess): |
46 |
+class EbuildFetcher(ForkProcess): |
47 |
|
48 |
__slots__ = ("config_pool", "ebuild_path", "fetchonly", "fetchall", |
49 |
"pkg", "prefetch") + \ |
50 |
@@ -152,7 +150,7 @@ class EbuildFetcher(SpawnProcess): |
51 |
settings["NOCOLOR"] = nocolor |
52 |
|
53 |
self._settings = settings |
54 |
- SpawnProcess._start(self) |
55 |
+ ForkProcess._start(self) |
56 |
|
57 |
# Free settings now since it's no longer needed in |
58 |
# this process (the subprocess has a private copy). |
59 |
@@ -160,28 +158,7 @@ class EbuildFetcher(SpawnProcess): |
60 |
settings = None |
61 |
self._settings = None |
62 |
|
63 |
- def _spawn(self, args, fd_pipes=None, **kwargs): |
64 |
- """ |
65 |
- Fork a subprocess, apply local settings, and call fetch(). |
66 |
- """ |
67 |
- |
68 |
- pid = os.fork() |
69 |
- if pid != 0: |
70 |
- if not isinstance(pid, int): |
71 |
- raise AssertionError( |
72 |
- "fork returned non-integer: %s" % (repr(pid),)) |
73 |
- portage.process.spawned_pids.append(pid) |
74 |
- return [pid] |
75 |
- |
76 |
- portage.locks._close_fds() |
77 |
- # Disable close_fds since we don't exec (see _setup_pipes docstring). |
78 |
- portage.process._setup_pipes(fd_pipes, close_fds=False) |
79 |
- |
80 |
- # Use default signal handlers in order to avoid problems |
81 |
- # killing subprocesses as reported in bug #353239. |
82 |
- signal.signal(signal.SIGINT, signal.SIG_DFL) |
83 |
- signal.signal(signal.SIGTERM, signal.SIG_DFL) |
84 |
- |
85 |
+ def _run(self): |
86 |
# Force consistent color output, in case we are capturing fetch |
87 |
# output through a normal pipe due to unavailability of ptys. |
88 |
portage.output.havecolor = self._settings.get('NOCOLOR') \ |
89 |
@@ -189,19 +166,11 @@ class EbuildFetcher(SpawnProcess): |
90 |
|
91 |
rval = 1 |
92 |
allow_missing = self._get_manifest().allow_missing |
93 |
- try: |
94 |
- if fetch(self._uri_map, self._settings, fetchonly=self.fetchonly, |
95 |
- digests=copy.deepcopy(self._get_digests()), |
96 |
- allow_missing_digests=allow_missing): |
97 |
- rval = os.EX_OK |
98 |
- except SystemExit: |
99 |
- raise |
100 |
- except: |
101 |
- traceback.print_exc() |
102 |
- finally: |
103 |
- # Call os._exit() from finally block, in order to suppress any |
104 |
- # finally blocks from earlier in the call stack. See bug #345289. |
105 |
- os._exit(rval) |
106 |
+ if fetch(self._uri_map, self._settings, fetchonly=self.fetchonly, |
107 |
+ digests=copy.deepcopy(self._get_digests()), |
108 |
+ allow_missing_digests=allow_missing): |
109 |
+ rval = os.EX_OK |
110 |
+ return rval |
111 |
|
112 |
def _get_ebuild_path(self): |
113 |
if self.ebuild_path is not None: |
114 |
@@ -301,7 +270,7 @@ class EbuildFetcher(SpawnProcess): |
115 |
self.scheduler.output(msg, log_path=self.logfile) |
116 |
|
117 |
def _set_returncode(self, wait_retval): |
118 |
- SpawnProcess._set_returncode(self, wait_retval) |
119 |
+ ForkProcess._set_returncode(self, wait_retval) |
120 |
# Collect elog messages that might have been |
121 |
# created by the pkg_nofetch phase. |
122 |
# Skip elog messages for prefetch, in order to avoid duplicates. |
123 |
|
124 |
diff --git a/pym/portage/dbapi/_MergeProcess.py b/pym/portage/dbapi/_MergeProcess.py |
125 |
index b5f6a0b..a9cc2b3 100644 |
126 |
--- a/pym/portage/dbapi/_MergeProcess.py |
127 |
+++ b/pym/portage/dbapi/_MergeProcess.py |
128 |
@@ -11,9 +11,9 @@ import fcntl |
129 |
import portage |
130 |
from portage import os, _unicode_decode |
131 |
import portage.elog.messages |
132 |
-from _emerge.SpawnProcess import SpawnProcess |
133 |
+from portage.util._async.ForkProcess import ForkProcess |
134 |
|
135 |
-class MergeProcess(SpawnProcess): |
136 |
+class MergeProcess(ForkProcess): |
137 |
""" |
138 |
Merge packages in a subprocess, so the Scheduler can run in the main |
139 |
thread while files are moved or copied asynchronously. |
140 |
@@ -101,7 +101,7 @@ class MergeProcess(SpawnProcess): |
141 |
def _spawn(self, args, fd_pipes, **kwargs): |
142 |
""" |
143 |
Fork a subprocess, apply local settings, and call |
144 |
- dblink.merge(). |
145 |
+ dblink.merge(). TODO: Share code with ForkProcess. |
146 |
""" |
147 |
|
148 |
elog_reader_fd, elog_writer_fd = os.pipe() |
149 |
|
150 |
diff --git a/pym/portage/util/_async/ForkProcess.py b/pym/portage/util/_async/ForkProcess.py |
151 |
index 607d0ff..6fcd662 100644 |
152 |
--- a/pym/portage/util/_async/ForkProcess.py |
153 |
+++ b/pym/portage/util/_async/ForkProcess.py |
154 |
@@ -10,6 +10,8 @@ from _emerge.SpawnProcess import SpawnProcess |
155 |
|
156 |
class ForkProcess(SpawnProcess): |
157 |
|
158 |
+ __slots__ = () |
159 |
+ |
160 |
def _spawn(self, args, fd_pipes=None, **kwargs): |
161 |
""" |
162 |
Fork a subprocess, apply local settings, and call fetch(). |