1 |
commit: 0e50583c165feedf24152dae1973af88e0005191 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Dec 31 10:29:42 2017 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jan 4 21:56:14 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=0e50583c |
7 |
|
8 |
multiprocessing.eclass: Remove multijob_* functions |
9 |
|
10 |
Remove the multijob functions that were used to run bash code |
11 |
in parallel. The code was very complex, fragile and unmaintained. It has |
12 |
been used scarcely, and pretty much by a single developer. It gave very |
13 |
little gain, usually at the cost of losing readability and violating |
14 |
PMS. |
15 |
|
16 |
Closes: https://bugs.gentoo.org/613322 |
17 |
|
18 |
eclass/multiprocessing.eclass | 178 +++------------------------------------- |
19 |
eclass/tests/multiprocessing.sh | 42 ---------- |
20 |
2 files changed, 10 insertions(+), 210 deletions(-) |
21 |
|
22 |
diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass |
23 |
index b6e92976f73..cfe22303043 100644 |
24 |
--- a/eclass/multiprocessing.eclass |
25 |
+++ b/eclass/multiprocessing.eclass |
26 |
@@ -1,4 +1,4 @@ |
27 |
-# Copyright 1999-2014 Gentoo Foundation |
28 |
+# Copyright 1999-2017 Gentoo Foundation |
29 |
# Distributed under the terms of the GNU General Public License v2 |
30 |
|
31 |
# @ECLASS: multiprocessing.eclass |
32 |
@@ -7,29 +7,20 @@ |
33 |
# @AUTHOR: |
34 |
# Brian Harring <ferringb@g.o> |
35 |
# Mike Frysinger <vapier@g.o> |
36 |
-# @BLURB: parallelization with bash (wtf?) |
37 |
+# @BLURB: multiprocessing helper functions |
38 |
# @DESCRIPTION: |
39 |
-# The multiprocessing eclass contains a suite of functions that allow ebuilds |
40 |
-# to quickly run things in parallel using shell code. |
41 |
+# The multiprocessing eclass contains a suite of utility functions |
42 |
+# that could be helpful to controlling parallel multiple job execution. |
43 |
+# The most common use is processing MAKEOPTS in order to obtain job |
44 |
+# count. |
45 |
# |
46 |
-# It has two modes: pre-fork and post-fork. If you don't want to dive into any |
47 |
-# more nuts & bolts, just use the pre-fork mode. For main threads that mostly |
48 |
-# spawn children and then wait for them to finish, use the pre-fork mode. For |
49 |
-# main threads that do a bit of processing themselves, use the post-fork mode. |
50 |
-# You may mix & match them for longer computation loops. |
51 |
# @EXAMPLE: |
52 |
# |
53 |
# @CODE |
54 |
-# # First initialize things: |
55 |
-# multijob_init |
56 |
-# |
57 |
-# # Then hash a bunch of files in parallel: |
58 |
-# for n in {0..20} ; do |
59 |
-# multijob_child_init md5sum data.${n} > data.${n} |
60 |
-# done |
61 |
-# |
62 |
-# # Then wait for all the children to finish: |
63 |
-# multijob_finish |
64 |
+# src_compile() { |
65 |
+# # custom build system that does not support most of MAKEOPTS |
66 |
+# ./mybs -j$(makeopts_jobs) |
67 |
+# } |
68 |
# @CODE |
69 |
|
70 |
if [[ -z ${_MULTIPROCESSING_ECLASS} ]]; then |
71 |
@@ -126,155 +117,6 @@ makeopts_loadavg() { |
72 |
echo ${lavg:-${2:-999}} |
73 |
} |
74 |
|
75 |
-# @FUNCTION: multijob_init |
76 |
-# @USAGE: [${MAKEOPTS}] |
77 |
-# @DESCRIPTION: |
78 |
-# Setup the environment for executing code in parallel. |
79 |
-# You must call this before any other multijob function. |
80 |
-multijob_init() { |
81 |
- # When something goes wrong, try to wait for all the children so we |
82 |
- # don't leave any zombies around. |
83 |
- has wait ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" wait " |
84 |
- |
85 |
- # Setup a pipe for children to write their pids to when they finish. |
86 |
- # We have to allocate two fd's because POSIX has undefined behavior |
87 |
- # when using one single fd for both read and write. #487056 |
88 |
- # However, opening an fd for read or write only will block until the |
89 |
- # opposite end is opened as well. Thus we open the first fd for both |
90 |
- # read and write to not block ourselve, but use it for reading only. |
91 |
- # The second fd really is opened for write only, as Cygwin supports |
92 |
- # just one single read fd per FIFO. #583962 |
93 |
- local pipe="${T}/multijob.pipe" |
94 |
- mkfifo -m 600 "${pipe}" |
95 |
- redirect_alloc_fd mj_read_fd "${pipe}" |
96 |
- redirect_alloc_fd mj_write_fd "${pipe}" '>' |
97 |
- rm -f "${pipe}" |
98 |
- |
99 |
- # See how many children we can fork based on the user's settings. |
100 |
- mj_max_jobs=$(makeopts_jobs "$@") |
101 |
- mj_num_jobs=0 |
102 |
-} |
103 |
- |
104 |
-# @FUNCTION: multijob_child_init |
105 |
-# @USAGE: [--pre|--post] [command to run in background] |
106 |
-# @DESCRIPTION: |
107 |
-# This function has two forms. You can use it to execute a simple command |
108 |
-# in the background (and it takes care of everything else), or you must |
109 |
-# call this first thing in your forked child process. |
110 |
-# |
111 |
-# The --pre/--post options allow you to select the child generation mode. |
112 |
-# |
113 |
-# @CODE |
114 |
-# # 1st form: pass the command line as arguments: |
115 |
-# multijob_child_init ls /dev |
116 |
-# # Or if you want to use pre/post fork modes: |
117 |
-# multijob_child_init --pre ls /dev |
118 |
-# multijob_child_init --post ls /dev |
119 |
-# |
120 |
-# # 2nd form: execute multiple stuff in the background (post fork): |
121 |
-# ( |
122 |
-# multijob_child_init |
123 |
-# out=`ls` |
124 |
-# if echo "${out}" | grep foo ; then |
125 |
-# echo "YEAH" |
126 |
-# fi |
127 |
-# ) & |
128 |
-# multijob_post_fork |
129 |
-# |
130 |
-# # 2nd form: execute multiple stuff in the background (pre fork): |
131 |
-# multijob_pre_fork |
132 |
-# ( |
133 |
-# multijob_child_init |
134 |
-# out=`ls` |
135 |
-# if echo "${out}" | grep foo ; then |
136 |
-# echo "YEAH" |
137 |
-# fi |
138 |
-# ) & |
139 |
-# @CODE |
140 |
-multijob_child_init() { |
141 |
- local mode="pre" |
142 |
- case $1 in |
143 |
- --pre) mode="pre" ; shift ;; |
144 |
- --post) mode="post"; shift ;; |
145 |
- esac |
146 |
- |
147 |
- if [[ $# -eq 0 ]] ; then |
148 |
- trap 'echo ${BASHPID:-$(bashpid)} $? >&'${mj_write_fd} EXIT |
149 |
- trap 'exit 1' INT TERM |
150 |
- else |
151 |
- local ret |
152 |
- [[ ${mode} == "pre" ]] && { multijob_pre_fork; ret=$?; } |
153 |
- ( multijob_child_init ; "$@" ) & |
154 |
- [[ ${mode} == "post" ]] && { multijob_post_fork; ret=$?; } |
155 |
- return ${ret} |
156 |
- fi |
157 |
-} |
158 |
- |
159 |
-# @FUNCTION: _multijob_fork |
160 |
-# @INTERNAL |
161 |
-# @DESCRIPTION: |
162 |
-# Do the actual book keeping. |
163 |
-_multijob_fork() { |
164 |
- [[ $# -eq 1 ]] || die "incorrect number of arguments" |
165 |
- |
166 |
- local ret=0 |
167 |
- [[ $1 == "post" ]] && : $(( ++mj_num_jobs )) |
168 |
- if [[ ${mj_num_jobs} -ge ${mj_max_jobs} ]] ; then |
169 |
- multijob_finish_one |
170 |
- ret=$? |
171 |
- fi |
172 |
- [[ $1 == "pre" ]] && : $(( ++mj_num_jobs )) |
173 |
- return ${ret} |
174 |
-} |
175 |
- |
176 |
-# @FUNCTION: multijob_pre_fork |
177 |
-# @DESCRIPTION: |
178 |
-# You must call this in the parent process before forking a child process. |
179 |
-# If the parallel limit has been hit, it will wait for one child to finish |
180 |
-# and return its exit status. |
181 |
-multijob_pre_fork() { _multijob_fork pre "$@" ; } |
182 |
- |
183 |
-# @FUNCTION: multijob_post_fork |
184 |
-# @DESCRIPTION: |
185 |
-# You must call this in the parent process after forking a child process. |
186 |
-# If the parallel limit has been hit, it will wait for one child to finish |
187 |
-# and return its exit status. |
188 |
-multijob_post_fork() { _multijob_fork post "$@" ; } |
189 |
- |
190 |
-# @FUNCTION: multijob_finish_one |
191 |
-# @DESCRIPTION: |
192 |
-# Wait for a single process to exit and return its exit code. |
193 |
-multijob_finish_one() { |
194 |
- [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments" |
195 |
- |
196 |
- local pid ret |
197 |
- read -r -u ${mj_read_fd} pid ret || die |
198 |
- : $(( --mj_num_jobs )) |
199 |
- return ${ret} |
200 |
-} |
201 |
- |
202 |
-# @FUNCTION: multijob_finish |
203 |
-# @DESCRIPTION: |
204 |
-# Wait for all pending processes to exit and return the bitwise or |
205 |
-# of all their exit codes. |
206 |
-multijob_finish() { |
207 |
- local ret=0 |
208 |
- while [[ ${mj_num_jobs} -gt 0 ]] ; do |
209 |
- multijob_finish_one |
210 |
- : $(( ret |= $? )) |
211 |
- done |
212 |
- # Let bash clean up its internal child tracking state. |
213 |
- wait |
214 |
- |
215 |
- # Do this after reaping all the children. |
216 |
- [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments" |
217 |
- |
218 |
- # No need to hook anymore. |
219 |
- EBUILD_DEATH_HOOKS=${EBUILD_DEATH_HOOKS/ wait / } |
220 |
- |
221 |
- return ${ret} |
222 |
-} |
223 |
- |
224 |
# @FUNCTION: redirect_alloc_fd |
225 |
# @USAGE: <var> <file> [redirection] |
226 |
# @DESCRIPTION: |
227 |
|
228 |
diff --git a/eclass/tests/multiprocessing.sh b/eclass/tests/multiprocessing.sh |
229 |
deleted file mode 100755 |
230 |
index 1ceb7f7fa7b..00000000000 |
231 |
--- a/eclass/tests/multiprocessing.sh |
232 |
+++ /dev/null |
233 |
@@ -1,42 +0,0 @@ |
234 |
-#!/bin/bash |
235 |
-# Copyright 1999-2015 Gentoo Foundation |
236 |
-# Distributed under the terms of the GNU General Public License v2 |
237 |
- |
238 |
-source tests-common.sh |
239 |
- |
240 |
-inherit multiprocessing |
241 |
- |
242 |
-tbegin "simple" |
243 |
-MAKEOPTS="-j1" multijob_init |
244 |
-multijob_child_init ls -d / >/dev/null || die "fail!" |
245 |
-multijob_finish |
246 |
-tend $? |
247 |
- |
248 |
-tbegin "less simple" |
249 |
-multijob_init -j3 |
250 |
-multijob_child_init true || die "fail!" |
251 |
-multijob_child_init false || die "fail!" |
252 |
-multijob_child_init true || die "fail!" |
253 |
-multijob_finish |
254 |
-tend $(( $? == 1 ? 0 : 1 )) |
255 |
- |
256 |
-tbegin "less less simple" |
257 |
-multijob_init -j1 |
258 |
-multijob_child_init true || die "fail!" |
259 |
-multijob_child_init false || die "fail!" |
260 |
-multijob_child_init true && die "fail!" |
261 |
-multijob_finish |
262 |
-tend $? |
263 |
- |
264 |
-tbegin "less less less simple" |
265 |
-multijob_init -j10 |
266 |
-multijob_child_init true || die "fail!" |
267 |
-multijob_finish_one || die "fail!" |
268 |
-multijob_child_init false || die "fail!" |
269 |
-multijob_finish_one && die "fail!" |
270 |
-multijob_child_init true || die "fail!" |
271 |
-multijob_finish_one || die "fail!" |
272 |
-multijob_finish |
273 |
-tend $? |
274 |
- |
275 |
-texit |