slave 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -10,23 +10,27 @@ SYNOPSIS
10
10
 
11
11
  typical usage:
12
12
 
13
- obj = AnyClass::new
13
+ slave = Slave::new{ AnyObject.new }
14
14
 
15
- slave = Slave::new 'object' => obj
15
+ slave.object #=> handle on drb object
16
+ slave.uri #=> uri of the drb object
17
+ slave.socket #=> unix domain socket path for drb object
18
+ slave.psname #=> title shown in ps/top
16
19
 
17
- p slave.object # handle on drb object
18
- p slave.uri # uri of the drb object
19
- p slave.socket # unix domain socket path for drb object
20
- p slave.psname # title shown in ps/top
20
+ object = slave.object
21
+
22
+ value = object.any_method #=> use the object normally
21
23
 
22
24
  slaves may be configured via the environment, the Slave class, or via the
23
25
  ctor for object itself. attributes which may be configured include
24
26
 
25
- * socket_creation_attempts
26
- * pulse_rate
27
- * psname
28
- * debug
29
- * dumped
27
+ * object : specify the slave object. otherwise block value is used.
28
+ * socket_creation_attempts : specify how many attempts to create a unix domain socket will be made
29
+ * debug : turn on some logging to STDERR
30
+ * psname : specify the name that will appear in 'top' ($0)
31
+ * at_exit : specify a lambda to be called in the *parent* when the child dies
32
+ * dumped : specify that the slave object should *not* be DRbUndumped (default is DRbUndumped)
33
+ * threadsafe : wrap the slave object with ThreadSafe to implement gross thread safety
30
34
 
31
35
  URIS
32
36
 
@@ -35,9 +39,22 @@ URIS
35
39
 
36
40
  HISTORY
37
41
 
38
- THIS RELEASE IS !! NOT !! BACKWARD COMPATIBLE. NOTE NEW CTOR SYNTAX.
42
+ 1.1.0:
43
+ - replaced HeartBeat class with LifeLine.
44
+
45
+ - __HUGE__ cleanup of file descriptor/fork management with tons of help
46
+ from skaar and ezra. thanks guys!
47
+
48
+ - introduced Slave.object method used to return any object directory from
49
+ a child process. see samples/g.rb.
50
+
51
+ - indroduced keyword to automatically make slave objects threadsafe.
52
+ remember that your slave object must be threadsafe because they are
53
+ being server via DRb!!!
54
+
39
55
 
40
56
  1.0.0:
57
+ - THIS RELEASE IS !! NOT !! BACKWARD COMPATIBLE. NOTE NEW CTOR SYNTAX.
41
58
 
42
59
  - detach method also sets up at_exit handler. extra protection from
43
60
  zombies.
@@ -97,9 +114,11 @@ SAMPLES
97
114
  end
98
115
 
99
116
  slave = Slave.new :object => Server.new
100
- server = slave.object
101
117
 
118
+ server = slave.object
102
119
  p server.add_two(40) #=> 42
120
+
121
+ slave.shutdown
103
122
 
104
123
  ~ > ruby samples/a.rb
105
124
 
@@ -136,7 +155,7 @@ SAMPLES
136
155
  ~ > ruby samples/b.rb
137
156
 
138
157
  :postgresql
139
- ./lib/slave.rb:276:in `initialize': undefined method `typo' for #<Server:0xb7573350> (NoMethodError)
158
+ ./lib/slave.rb:460:in `initialize': undefined method `typo' for #<Server:0xb7565694> (NoMethodError)
140
159
  from samples/b.rb:22:in `new'
141
160
  from samples/b.rb:22
142
161
 
@@ -169,9 +188,9 @@ SAMPLES
169
188
 
170
189
  ~ > ruby samples/c.rb
171
190
 
172
- 12244
173
- 12245
174
- ./lib/slave.rb:276:in `initialize': undefined local variable or method `fubar' for main:Object (NameError)
191
+ 14387
192
+ 14388
193
+ ./lib/slave.rb:460:in `initialize': undefined local variable or method `fubar' for main:Object (NameError)
175
194
  from samples/c.rb:21:in `new'
176
195
  from samples/c.rb:21
177
196
 
@@ -192,6 +211,7 @@ SAMPLES
192
211
 
193
212
  ~ > ruby samples/d.rb
194
213
 
214
+ "child"
195
215
  "parent"
196
216
 
197
217
 
@@ -215,3 +235,56 @@ SAMPLES
215
235
 
216
236
  "child"
217
237
 
238
+
239
+ <========< samples/f.rb >========>
240
+
241
+ ~ > cat samples/f.rb
242
+
243
+ require 'slave'
244
+ #
245
+ # slaves created previously are visible to newly created slaves - in this
246
+ # example the child process of slave_a communicates directly with the child
247
+ # process of slave_a
248
+ #
249
+ slave_a = Slave.new{ Array.new }
250
+ slave_b = Slave.new{ slave_a.object }
251
+
252
+ a, b = slave_b.object, slave_a.object
253
+
254
+ b << 42
255
+ puts a #=> 42
256
+
257
+ ~ > ruby samples/f.rb
258
+
259
+ 42
260
+
261
+
262
+ <========< samples/g.rb >========>
263
+
264
+ ~ > cat samples/g.rb
265
+
266
+ require 'slave'
267
+ #
268
+ # Slave.object can used when you want to construct an object in another
269
+ # process. in otherwords you want to fork a process and retrieve a single
270
+ # returned object from that process as opposed to setting up a server.
271
+ #
272
+ this = Process.pid
273
+ that = Slave.object{ Process.pid }
274
+
275
+ p 'this' => this, 'that' => that
276
+
277
+ #
278
+ # any object can be returned and it can be returned asychronously via a thread
279
+ #
280
+ thread = Slave.object(:async => true){ sleep 2 and [ Process.pid, Time.now ] }
281
+ this = [ Process.pid, Time.now ]
282
+ that = thread.value
283
+
284
+ p 'this' => this, 'that' => that
285
+
286
+ ~ > ruby samples/g.rb
287
+
288
+ {"that"=>14406, "this"=>14405}
289
+ {"that"=>[14407, Tue Nov 28 09:47:31 MST 2006], "this"=>[14405, Tue Nov 28 09:47:29 MST 2006]}
290
+
data/README.tmpl CHANGED
@@ -10,23 +10,27 @@ SYNOPSIS
10
10
 
11
11
  typical usage:
12
12
 
13
- obj = AnyClass::new
13
+ slave = Slave::new{ AnyObject.new }
14
14
 
15
- slave = Slave::new 'object' => obj
15
+ slave.object #=> handle on drb object
16
+ slave.uri #=> uri of the drb object
17
+ slave.socket #=> unix domain socket path for drb object
18
+ slave.psname #=> title shown in ps/top
16
19
 
17
- p slave.object # handle on drb object
18
- p slave.uri # uri of the drb object
19
- p slave.socket # unix domain socket path for drb object
20
- p slave.psname # title shown in ps/top
20
+ object = slave.object
21
+
22
+ value = object.any_method #=> use the object normally
21
23
 
22
24
  slaves may be configured via the environment, the Slave class, or via the
23
25
  ctor for object itself. attributes which may be configured include
24
26
 
25
- * socket_creation_attempts
26
- * pulse_rate
27
- * psname
28
- * debug
29
- * dumped
27
+ * object : specify the slave object. otherwise block value is used.
28
+ * socket_creation_attempts : specify how many attempts to create a unix domain socket will be made
29
+ * debug : turn on some logging to STDERR
30
+ * psname : specify the name that will appear in 'top' ($0)
31
+ * at_exit : specify a lambda to be called in the *parent* when the child dies
32
+ * dumped : specify that the slave object should *not* be DRbUndumped (default is DRbUndumped)
33
+ * threadsafe : wrap the slave object with ThreadSafe to implement gross thread safety
30
34
 
31
35
  URIS
32
36
 
@@ -35,9 +39,22 @@ URIS
35
39
 
36
40
  HISTORY
37
41
 
38
- THIS RELEASE IS !! NOT !! BACKWARD COMPATIBLE. NOTE NEW CTOR SYNTAX.
42
+ 1.1.0:
43
+ - replaced HeartBeat class with LifeLine.
44
+
45
+ - __HUGE__ cleanup of file descriptor/fork management with tons of help
46
+ from skaar and ezra. thanks guys!
47
+
48
+ - introduced Slave.object method used to return any object directory from
49
+ a child process. see samples/g.rb.
50
+
51
+ - indroduced keyword to automatically make slave objects threadsafe.
52
+ remember that your slave object must be threadsafe because they are
53
+ being server via DRb!!!
54
+
39
55
 
40
56
  1.0.0:
57
+ - THIS RELEASE IS !! NOT !! BACKWARD COMPATIBLE. NOTE NEW CTOR SYNTAX.
41
58
 
42
59
  - detach method also sets up at_exit handler. extra protection from
43
60
  zombies.
@@ -84,9 +84,9 @@
84
84
  <div id="description">
85
85
  <p>
86
86
  the <a href="Slave.html">Slave</a> class encapsulates the work of setting
87
- up a drb server in another process running on localhost. the slave process
88
- is attached to it&#8217;s parent via a <a
89
- href="Slave/Heartbeat.html">Heartbeat</a> which is designed such that the
87
+ up a drb server in another process running on localhost via unix domain
88
+ sockets. the slave process is attached to it&#8217;s parent via a <a
89
+ href="Slave/LifeLine.html">LifeLine</a> which is designed such that the
90
90
  slave cannot out-live it&#8217;s parent and become a zombie, even if the
91
91
  parent dies and early death, such as by &#8216;kill -9&#8217;. the concept
92
92
  and purpose of the <a href="Slave.html">Slave</a> class is to be able to
@@ -138,6 +138,8 @@ of the two &#8216;b&#8217; is preferred.
138
138
  <a href="#M000003">getopts</a>&nbsp;&nbsp;
139
139
  <a href="#M000013">getopts</a>&nbsp;&nbsp;
140
140
  <a href="#M000005">new</a>&nbsp;&nbsp;
141
+ <a href="#M000015">object</a>&nbsp;&nbsp;
142
+ <a href="#M000016">object</a>&nbsp;&nbsp;
141
143
  <a href="#M000009">shutdown</a>&nbsp;&nbsp;
142
144
  <a href="#M000010">shutdown?</a>&nbsp;&nbsp;
143
145
  <a href="#M000014">trace</a>&nbsp;&nbsp;
@@ -155,7 +157,7 @@ of the two &#8216;b&#8217; is preferred.
155
157
  <tr class="top-aligned-row context-row">
156
158
  <td class="context-item-name">VERSION</td>
157
159
  <td>=</td>
158
- <td class="context-item-value">'1.0.0'</td>
160
+ <td class="context-item-value">'1.1.0'</td>
159
161
  </tr>
160
162
  <tr class="top-aligned-row context-row">
161
163
  <td class="context-item-name">DEFAULT_SOCKET_CREATION_ATTEMPTS</td>
@@ -165,19 +167,19 @@ of the two &#8216;b&#8217; is preferred.
165
167
  <tr class="top-aligned-row context-row">
166
168
  <td>&nbsp;</td>
167
169
  <td colspan="2" class="context-item-desc">
168
- config
170
+ env config
169
171
 
170
172
  </td>
171
173
  </tr>
172
174
  <tr class="top-aligned-row context-row">
173
- <td class="context-item-name">DEFAULT_PULSE_RATE</td>
175
+ <td class="context-item-name">DEFAULT_DEBUG</td>
174
176
  <td>=</td>
175
- <td class="context-item-value">Float(ENV['SLAVE_PULSE_RATE'] || 8)</td>
177
+ <td class="context-item-value">(ENV['SLAVE_DEBUG'] ? true : false)</td>
176
178
  </tr>
177
179
  <tr class="top-aligned-row context-row">
178
- <td class="context-item-name">DEFAULT_DEBUG</td>
180
+ <td class="context-item-name">DEFAULT_THREADSAFE</td>
179
181
  <td>=</td>
180
- <td class="context-item-value">(ENV['SLAVE_DEBUG'] ? true : false)</td>
182
+ <td class="context-item-value">(ENV['SLAVE_THREADSAFE'] ? true : false)</td>
181
183
  </tr>
182
184
  </table>
183
185
  </div>
@@ -210,10 +212,18 @@ on STDERR
210
212
  <td class="context-item-desc"></td>
211
213
  </tr>
212
214
  <tr class="top-aligned-row context-row">
213
- <td class="context-item-name">obj</td>
215
+ <td class="context-item-name">dumped</td>
214
216
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
215
217
  <td class="context-item-desc"></td>
216
218
  </tr>
219
+ <tr class="top-aligned-row context-row">
220
+ <td class="context-item-name">obj</td>
221
+ <td class="context-item-value">&nbsp;[R]&nbsp;</td>
222
+ <td class="context-item-desc">
223
+ attrs
224
+
225
+ </td>
226
+ </tr>
217
227
  <tr class="top-aligned-row context-row">
218
228
  <td class="context-item-name">object</td>
219
229
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
@@ -234,20 +244,6 @@ on STDERR
234
244
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
235
245
  <td class="context-item-desc"></td>
236
246
  </tr>
237
- <tr class="top-aligned-row context-row">
238
- <td class="context-item-name">pulse_rate</td>
239
- <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
240
- <td class="context-item-desc">
241
- defined the rate of pinging in the <a
242
- href="Slave/Heartbeat.html">Heartbeat</a> object
243
-
244
- </td>
245
- </tr>
246
- <tr class="top-aligned-row context-row">
247
- <td class="context-item-name">pulse_rate</td>
248
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
249
- <td class="context-item-desc"></td>
250
- </tr>
251
247
  <tr class="top-aligned-row context-row">
252
248
  <td class="context-item-name">shutdown</td>
253
249
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
@@ -273,6 +269,17 @@ href="Slave/Heartbeat.html">Heartbeat</a> object
273
269
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
274
270
  <td class="context-item-desc"></td>
275
271
  </tr>
272
+ <tr class="top-aligned-row context-row">
273
+ <td class="context-item-name">threadsafe</td>
274
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
275
+ <td class="context-item-desc">
276
+ if this is true all slave objects will be wrapped such that any call to the
277
+ object is threadsafe. if you do not use this you must ensure that your
278
+ objects are threadsafe <em>yourself</em> as this is required of any object
279
+ acting as a drb server
280
+
281
+ </td>
282
+ </tr>
276
283
  <tr class="top-aligned-row context-row">
277
284
  <td class="context-item-name">uri</td>
278
285
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
@@ -285,7 +292,9 @@ href="Slave/Heartbeat.html">Heartbeat</a> object
285
292
  <div id="class-list">
286
293
  <h2 class="section-bar">Classes and Modules</h2>
287
294
 
288
- Class <a href="Slave/Heartbeat.html" class="link">Slave::Heartbeat</a><br />
295
+ Class <a href="Slave/LifeLine.html" class="link">Slave::LifeLine</a><br />
296
+ Class <a href="Slave/ThreadSafe.html" class="link">Slave::ThreadSafe</a><br />
297
+ Class <a href="Slave/ThreadSafeHash.html" class="link">Slave::ThreadSafeHash</a><br />
289
298
 
290
299
  </div>
291
300
 
@@ -317,12 +326,12 @@ get a default value
317
326
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
318
327
  <div class="method-source-code" id="M000002-source">
319
328
  <pre>
320
- <span class="ruby-comment cmt"># File lib/slave.rb, line 73</span>
321
- 73: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
322
- 74: <span class="ruby-comment cmt">#--{{{</span>
323
- 75: <span class="ruby-identifier">send</span> <span class="ruby-identifier">key</span>
324
- 76: <span class="ruby-comment cmt">#--}}}</span>
325
- 77: <span class="ruby-keyword kw">end</span>
329
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 77</span>
330
+ 77: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
331
+ 78: <span class="ruby-comment cmt">#--{{{</span>
332
+ 79: <span class="ruby-identifier">send</span> <span class="ruby-identifier">key</span>
333
+ 80: <span class="ruby-comment cmt">#--}}}</span>
334
+ 81: <span class="ruby-keyword kw">end</span>
326
335
  </pre>
327
336
  </div>
328
337
  </div>
@@ -345,18 +354,18 @@ just fork with out silly warnings
345
354
  onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
346
355
  <div class="method-source-code" id="M000004-source">
347
356
  <pre>
348
- <span class="ruby-comment cmt"># File lib/slave.rb, line 94</span>
349
- 94: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fork</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
350
- 95: <span class="ruby-comment cmt">#--{{{</span>
351
- 96: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">$VERBOSE</span>
352
- 97: <span class="ruby-keyword kw">begin</span>
353
- 98: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-keyword kw">nil</span>
354
- 99: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">fork</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
355
- 100: <span class="ruby-keyword kw">ensure</span>
356
- 101: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">v</span>
357
- 102: <span class="ruby-keyword kw">end</span>
358
- 103: <span class="ruby-comment cmt">#--}}}</span>
359
- 104: <span class="ruby-keyword kw">end</span>
357
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 98</span>
358
+ 98: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fork</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
359
+ 99: <span class="ruby-comment cmt">#--{{{</span>
360
+ 100: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">$VERBOSE</span>
361
+ 101: <span class="ruby-keyword kw">begin</span>
362
+ 102: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-keyword kw">nil</span>
363
+ 103: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">fork</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
364
+ 104: <span class="ruby-keyword kw">ensure</span>
365
+ 105: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">v</span>
366
+ 106: <span class="ruby-keyword kw">end</span>
367
+ 107: <span class="ruby-comment cmt">#--}}}</span>
368
+ 108: <span class="ruby-keyword kw">end</span>
360
369
  </pre>
361
370
  </div>
362
371
  </div>
@@ -376,20 +385,20 @@ just fork with out silly warnings
376
385
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
377
386
  <div class="method-source-code" id="M000003-source">
378
387
  <pre>
379
- <span class="ruby-comment cmt"># File lib/slave.rb, line 79</span>
380
- 79: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
381
- 80: <span class="ruby-comment cmt">#--{{{</span>
382
- 81: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">class</span> <span class="ruby-keyword kw">unless</span>
383
- 82: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'has_key?'</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'[]'</span>)
384
- 83:
385
- 84: <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">defval</span><span class="ruby-operator">|</span>
386
- 85: <span class="ruby-identifier">defval</span> = <span class="ruby-identifier">defval</span>.<span class="ruby-identifier">shift</span>
387
- 86: <span class="ruby-identifier">keys</span> = [<span class="ruby-identifier">key</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">intern</span>]
388
- 87: <span class="ruby-identifier">key</span> = <span class="ruby-identifier">keys</span>.<span class="ruby-identifier">detect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">k</span> } <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">break</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">key</span>]
389
- 88: <span class="ruby-identifier">defval</span>
390
- 89: <span class="ruby-keyword kw">end</span>
391
- 90: <span class="ruby-comment cmt">#--}}}</span>
392
- 91: <span class="ruby-keyword kw">end</span>
388
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 83</span>
389
+ 83: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
390
+ 84: <span class="ruby-comment cmt">#--{{{</span>
391
+ 85: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">class</span> <span class="ruby-keyword kw">unless</span>
392
+ 86: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'has_key?'</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'[]'</span>)
393
+ 87:
394
+ 88: <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">defval</span><span class="ruby-operator">|</span>
395
+ 89: <span class="ruby-identifier">defval</span> = <span class="ruby-identifier">defval</span>.<span class="ruby-identifier">shift</span>
396
+ 90: <span class="ruby-identifier">keys</span> = [<span class="ruby-identifier">key</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">intern</span>]
397
+ 91: <span class="ruby-identifier">key</span> = <span class="ruby-identifier">keys</span>.<span class="ruby-identifier">detect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">k</span> } <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">break</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">key</span>]
398
+ 92: <span class="ruby-identifier">defval</span>
399
+ 93: <span class="ruby-keyword kw">end</span>
400
+ 94: <span class="ruby-comment cmt">#--}}}</span>
401
+ 95: <span class="ruby-keyword kw">end</span>
393
402
  </pre>
394
403
  </div>
395
404
  </div>
@@ -406,173 +415,293 @@ just fork with out silly warnings
406
415
 
407
416
  <div class="method-description">
408
417
  <p>
409
- opts may contain the keys &#8216;object&#8217;,
410
- &#8216;socket_creation_attempts&#8217;, &#8216;pulse_rate&#8217;,
411
- &#8216;psname&#8217;, &#8216;dumped&#8217;, or &#8216;debug&#8217;
418
+ sets up a child process serving any object as a DRb server running locally
419
+ on unix domain sockets. the child process has a <a
420
+ href="Slave/LifeLine.html">LifeLine</a> established between it and the
421
+ parent, making it impossible for the child to outlive the parent (become a
422
+ zombie). the object to serve is specfied either directly using the
423
+ &#8216;object&#8217;/:object keyword
412
424
  </p>
425
+ <pre>
426
+ Slave.new :object =&gt; MyServer.new
427
+ </pre>
428
+ <p>
429
+ or, preferably, using the block form
430
+ </p>
431
+ <pre>
432
+ Slave.new{ MyServer.new }
433
+ </pre>
434
+ <p>
435
+ when the block form is used the object is contructed in the child process
436
+ itself. this is quite advantageous if the child object consumes resources
437
+ or opens file handles (db connections, etc). by contructing the object in
438
+ the child any resources are consumed from the child&#8217;s address space
439
+ and things like open file handles will not be carried into subsequent child
440
+ processes (via standard unix fork semantics). in the event that a block is
441
+ specified but the object cannot be constructed and, instead, throws and
442
+ Exception, that exception will be propogated to the parent process.
443
+ </p>
444
+ <p>
445
+ opts may contain the following keys, as either strings or symbols
446
+ </p>
447
+ <pre>
448
+ object : specify the slave object. otherwise block value is used.
449
+ socket_creation_attempts : specify how many attempts to create a unix domain socket will be made
450
+ debug : turn on some logging to STDERR
451
+ psname : specify the name that will appear in 'top' ($0)
452
+ at_exit : specify a lambda to be called in the *parent* when the child dies
453
+ dumped : specify that the slave object should *not* be DRbUndumped (default is DRbUndumped)
454
+ threadsafe : wrap the slave object with ThreadSafe to implement gross thread safety
455
+ </pre>
413
456
  <p><a class="source-toggle" href="#"
414
457
  onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
415
458
  <div class="method-source-code" id="M000005-source">
416
459
  <pre>
417
- <span class="ruby-comment cmt"># File lib/slave.rb, line 128</span>
418
- 128: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
419
- 129: <span class="ruby-comment cmt">#--{{{</span>
420
- 130: <span class="ruby-identifier">getopt</span> = <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
421
- 131:
422
- 132: <span class="ruby-ivar">@obj</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'object'</span>]
423
- 133: <span class="ruby-ivar">@socket_creation_attempts</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'socket_creation_attempts'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'socket_creation_attempts'</span>)
424
- 134: <span class="ruby-ivar">@pulse_rate</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'pulse_rate'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'pulse_rate'</span>)
425
- 135: <span class="ruby-ivar">@debug</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'debug'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'debug'</span>)
426
- 136: <span class="ruby-ivar">@psname</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'psname'</span>]
427
- 137: <span class="ruby-ivar">@at_exit</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'at_exit'</span>]
428
- 138: <span class="ruby-ivar">@dumped</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'dumped'</span>]
429
- 139:
430
- 140: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'no slave object!'</span> <span class="ruby-keyword kw">if</span>
431
- 141: <span class="ruby-ivar">@obj</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">nil?</span>
432
- 142:
433
- 143: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">false</span>
434
- 144: <span class="ruby-ivar">@waiter</span> = <span class="ruby-ivar">@status</span> = <span class="ruby-keyword kw">nil</span>
435
- 145:
436
- 146: <span class="ruby-ivar">@heartbeat</span> = <span class="ruby-constant">Heartbeat</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span> <span class="ruby-ivar">@pulse_rate</span>, <span class="ruby-ivar">@debug</span>
437
- 147: <span class="ruby-ivar">@r</span>, <span class="ruby-ivar">@w</span> = <span class="ruby-constant">IO</span><span class="ruby-operator">::</span><span class="ruby-identifier">pipe</span>
438
- 148: <span class="ruby-ivar">@r2</span>, <span class="ruby-ivar">@w2</span> = <span class="ruby-constant">IO</span><span class="ruby-operator">::</span><span class="ruby-identifier">pipe</span>
439
- 149:
440
- 150: <span class="ruby-comment cmt"># weird syntax because dot/rdoc chokes on this!?!?</span>
441
- 151: <span class="ruby-identifier">init_failure</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
442
- 152: <span class="ruby-identifier">o</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
443
- 153: <span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">o</span>
444
- 154: <span class="ruby-identifier">attr_accessor</span> <span class="ruby-value str">'__slave_object_failure__'</span>
445
- 155: <span class="ruby-keyword kw">end</span>
446
- 156: <span class="ruby-identifier">o</span>.<span class="ruby-identifier">__slave_object_failure__</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span> [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>]
447
- 157: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">o</span>
448
- 158: <span class="ruby-keyword kw">end</span>
449
- 159:
450
- 160: <span class="ruby-comment cmt">#</span>
451
- 161: <span class="ruby-comment cmt"># child</span>
452
- 162: <span class="ruby-comment cmt">#</span>
453
- 163: <span class="ruby-keyword kw">unless</span>((<span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Slave</span><span class="ruby-operator">::</span><span class="ruby-identifier">fork</span>))
454
- 164: <span class="ruby-identifier">e</span> = <span class="ruby-keyword kw">nil</span>
455
- 165: <span class="ruby-keyword kw">begin</span>
456
- 166: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span>{ <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">exit!</span> }
457
- 167:
458
- 168: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@obj</span>
459
- 169: <span class="ruby-ivar">@object</span> = <span class="ruby-ivar">@obj</span>
460
- 170: <span class="ruby-keyword kw">else</span>
461
- 171: <span class="ruby-keyword kw">begin</span>
462
- 172: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
463
- 173: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
464
- 174: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
465
- 175: <span class="ruby-keyword kw">end</span>
466
- 176: <span class="ruby-keyword kw">end</span>
467
- 177:
468
- 178: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@obj</span>
469
- 179: <span class="ruby-keyword kw">begin</span>
470
- 180: <span class="ruby-identifier">block</span>[<span class="ruby-ivar">@obj</span>]
471
- 181: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
472
- 182: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
473
- 183: <span class="ruby-keyword kw">end</span>
474
- 184: <span class="ruby-keyword kw">end</span>
475
- 185:
476
- 186: <span class="ruby-identifier">$0</span> = (<span class="ruby-ivar">@psname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@object</span>))
477
- 187: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@dumped</span> <span class="ruby-keyword kw">or</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'__slave_object_failure__'</span>)
478
- 188: <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">DRbUndumped</span>
479
- 189: <span class="ruby-keyword kw">end</span>
480
- 190:
481
- 191: <span class="ruby-ivar">@ppid</span>, <span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">ppid</span>, <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">pid</span>
482
- 192:
483
- 193: <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">close</span>
484
- 194: <span class="ruby-ivar">@r2</span>.<span class="ruby-identifier">close</span>
485
- 195: <span class="ruby-ivar">@socket</span> = <span class="ruby-keyword kw">nil</span>
486
- 196: <span class="ruby-ivar">@uri</span> = <span class="ruby-keyword kw">nil</span>
487
- 197:
488
- 198: <span class="ruby-identifier">tmpdir</span>, <span class="ruby-identifier">basename</span> = <span class="ruby-constant">Dir</span><span class="ruby-operator">::</span><span class="ruby-identifier">tmpdir</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">basename</span>(<span class="ruby-ivar">@psname</span>)
489
- 199:
490
- 200: <span class="ruby-ivar">@socket_creation_attempts</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attempt</span><span class="ruby-operator">|</span>
491
- 201: <span class="ruby-identifier">se</span> = <span class="ruby-keyword kw">nil</span>
492
- 202: <span class="ruby-keyword kw">begin</span>
493
- 203: <span class="ruby-identifier">s</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">join</span>(<span class="ruby-identifier">tmpdir</span>, <span class="ruby-node">&quot;#{ basename }_#{ attempt }&quot;</span>)
494
- 204: <span class="ruby-identifier">u</span> = <span class="ruby-node">&quot;drbunix://#{ s }&quot;</span>
495
- 205: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span> <span class="ruby-identifier">u</span>, <span class="ruby-ivar">@object</span>
496
- 206: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">s</span>
497
- 207: <span class="ruby-ivar">@uri</span> = <span class="ruby-identifier">u</span>
498
- 208: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;child - socket &lt;#{ @socket }&gt;&quot;</span> }
499
- 209: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;child - uri &lt;#{ @uri }&gt;&quot;</span> }
500
- 210: <span class="ruby-keyword kw">break</span>
501
- 211: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EADDRINUSE</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">se</span>
502
- 212: <span class="ruby-keyword kw">nil</span>
503
- 213: <span class="ruby-keyword kw">end</span>
504
- 214: <span class="ruby-keyword kw">end</span>
505
- 215:
506
- 216: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@uri</span>
507
- 217: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">start</span>
508
- 218:
509
- 219: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">'SIGUSR2'</span>) <span class="ruby-keyword kw">do</span>
510
- 220: <span class="ruby-comment cmt"># @heartbeat.stop rescue nil</span>
511
- 221: <span class="ruby-constant">DBb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>.<span class="ruby-identifier">kill</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
512
- 222: <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
513
- 223: <span class="ruby-identifier">exit</span>
514
- 224: <span class="ruby-keyword kw">end</span>
515
- 225:
516
- 226: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">write</span> <span class="ruby-ivar">@socket</span>
517
- 227: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
518
- 228: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>.<span class="ruby-identifier">join</span>
519
- 229: <span class="ruby-keyword kw">else</span>
520
- 230: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
521
- 231: <span class="ruby-keyword kw">end</span>
522
- 232: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
523
- 233: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join &quot;\n&quot; }]</span> }
524
- 234: <span class="ruby-keyword kw">ensure</span>
525
- 235: <span class="ruby-identifier">status</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'status'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">:</span> <span class="ruby-value">1</span>
526
- 236: <span class="ruby-identifier">exit</span>(<span class="ruby-identifier">status</span>)
527
- 237: <span class="ruby-keyword kw">end</span>
528
- 238: <span class="ruby-comment cmt">#</span>
529
- 239: <span class="ruby-comment cmt"># parent </span>
530
- 240: <span class="ruby-comment cmt">#</span>
531
- 241: <span class="ruby-keyword kw">else</span>
532
- 242: <span class="ruby-identifier">detach</span>
533
- 243: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
534
- 244: <span class="ruby-ivar">@w2</span>.<span class="ruby-identifier">close</span>
535
- 245: <span class="ruby-ivar">@socket</span> = <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">read</span>
536
- 246: <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">close</span>
537
- 247:
538
- 248: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;parent - socket &lt;#{ @socket }&gt;&quot;</span> }
539
- 249:
540
- 250: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@at_exit</span>
541
- 251: <span class="ruby-ivar">@at_exit_thread</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{
542
- 252: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>.<span class="ruby-identifier">abort_on_exception</span> = <span class="ruby-keyword kw">true</span>
543
- 253:
544
- 254: <span class="ruby-ivar">@r2</span>.<span class="ruby-identifier">read</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-value">42</span>
545
- 255:
546
- 256: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value str">'call'</span>
547
- 257: <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">self</span>
548
- 258: <span class="ruby-keyword kw">else</span>
549
- 259: <span class="ruby-identifier">send</span> <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-keyword kw">self</span>
550
- 260: <span class="ruby-keyword kw">end</span>
551
- 261: }
552
- 262: <span class="ruby-keyword kw">end</span>
553
- 263:
554
- 264: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">exist?</span> <span class="ruby-ivar">@socket</span>
555
- 265: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span>{ <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span> }
556
- 266: <span class="ruby-ivar">@uri</span> = <span class="ruby-node">&quot;drbunix://#{ socket }&quot;</span>
557
- 267: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;parent - uri &lt;#{ @uri }&gt;&quot;</span> }
558
- 268: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">start</span>
559
- 269: <span class="ruby-comment cmt">#</span>
560
- 270: <span class="ruby-comment cmt"># starting drb on localhost avoids dns lookups!</span>
561
- 271: <span class="ruby-comment cmt">#</span>
562
- 272: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span>(<span class="ruby-value str">'druby://localhost:0'</span>, <span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>
563
- 273: <span class="ruby-ivar">@object</span> = <span class="ruby-constant">DRbObject</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-ivar">@uri</span>
564
- 274: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value str">'__slave_object_failure__'</span>
565
- 275: <span class="ruby-identifier">c</span>, <span class="ruby-identifier">m</span>, <span class="ruby-identifier">bt</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">__slave_object_failure__</span>
566
- 276: (<span class="ruby-identifier">e</span> = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>)).<span class="ruby-identifier">set_backtrace</span> <span class="ruby-identifier">bt</span>
567
- 277: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
568
- 278: <span class="ruby-keyword kw">end</span>
569
- 279: <span class="ruby-ivar">@psname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@object</span>)
570
- 280: <span class="ruby-keyword kw">else</span>
571
- 281: <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;failed to find slave socket &lt;#{ @socket }&gt;&quot;</span>
572
- 282: <span class="ruby-keyword kw">end</span>
573
- 283: <span class="ruby-keyword kw">end</span>
574
- 284: <span class="ruby-comment cmt">#--}}}</span>
575
- 285: <span class="ruby-keyword kw">end</span>
460
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 321</span>
461
+ 321: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
462
+ 322: <span class="ruby-comment cmt">#--{{{</span>
463
+ 323: <span class="ruby-identifier">getopt</span> = <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
464
+ 324:
465
+ 325: <span class="ruby-ivar">@obj</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'object'</span>]
466
+ 326: <span class="ruby-ivar">@socket_creation_attempts</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'socket_creation_attempts'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'socket_creation_attempts'</span>)
467
+ 327: <span class="ruby-ivar">@debug</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'debug'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'debug'</span>)
468
+ 328: <span class="ruby-ivar">@psname</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'psname'</span>]
469
+ 329: <span class="ruby-ivar">@at_exit</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'at_exit'</span>]
470
+ 330: <span class="ruby-ivar">@dumped</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'dumped'</span>]
471
+ 331: <span class="ruby-ivar">@threadsafe</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'threadsafe'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'threadsafe'</span>)
472
+ 332:
473
+ 333: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'no slave object or slave object block provided!'</span> <span class="ruby-keyword kw">if</span>
474
+ 334: <span class="ruby-ivar">@obj</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">nil?</span>
475
+ 335:
476
+ 336: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">false</span>
477
+ 337: <span class="ruby-ivar">@waiter</span> = <span class="ruby-ivar">@status</span> = <span class="ruby-keyword kw">nil</span>
478
+ 338: <span class="ruby-ivar">@lifeline</span> = <span class="ruby-constant">LifeLine</span>.<span class="ruby-identifier">new</span>
479
+ 339:
480
+ 340: <span class="ruby-comment cmt"># weird syntax because dot/rdoc chokes on this!?!?</span>
481
+ 341: <span class="ruby-identifier">init_failure</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
482
+ 342: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join &quot;\n&quot; }]</span> }
483
+ 343: <span class="ruby-identifier">o</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
484
+ 344: <span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">o</span>
485
+ 345: <span class="ruby-identifier">attr_accessor</span> <span class="ruby-value str">'__slave_object_failure__'</span>
486
+ 346: <span class="ruby-keyword kw">end</span>
487
+ 347: <span class="ruby-identifier">o</span>.<span class="ruby-identifier">__slave_object_failure__</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span> [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>]
488
+ 348: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">o</span>
489
+ 349: <span class="ruby-keyword kw">end</span>
490
+ 350:
491
+ 351: <span class="ruby-comment cmt">#</span>
492
+ 352: <span class="ruby-comment cmt"># child</span>
493
+ 353: <span class="ruby-comment cmt">#</span>
494
+ 354: <span class="ruby-keyword kw">unless</span>((<span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Slave</span><span class="ruby-operator">::</span><span class="ruby-identifier">fork</span>))
495
+ 355: <span class="ruby-identifier">e</span> = <span class="ruby-keyword kw">nil</span>
496
+ 356: <span class="ruby-keyword kw">begin</span>
497
+ 357: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span>{ <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">exit!</span> }
498
+ 358: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">catch</span>
499
+ 359:
500
+ 360: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@obj</span>
501
+ 361: <span class="ruby-ivar">@object</span> = <span class="ruby-ivar">@obj</span>
502
+ 362: <span class="ruby-keyword kw">else</span>
503
+ 363: <span class="ruby-keyword kw">begin</span>
504
+ 364: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
505
+ 365: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
506
+ 366: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
507
+ 367: <span class="ruby-keyword kw">end</span>
508
+ 368: <span class="ruby-keyword kw">end</span>
509
+ 369:
510
+ 370: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@obj</span>
511
+ 371: <span class="ruby-keyword kw">begin</span>
512
+ 372: <span class="ruby-identifier">block</span>[<span class="ruby-ivar">@obj</span>]
513
+ 373: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
514
+ 374: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
515
+ 375: <span class="ruby-keyword kw">end</span>
516
+ 376: <span class="ruby-keyword kw">end</span>
517
+ 377:
518
+ 378: <span class="ruby-identifier">$0</span> = (<span class="ruby-ivar">@psname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@object</span>))
519
+ 379:
520
+ 380: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@dumped</span> <span class="ruby-keyword kw">or</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'__slave_object_failure__'</span>)
521
+ 381: <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">DRbUndumped</span>
522
+ 382: <span class="ruby-keyword kw">end</span>
523
+ 383:
524
+ 384: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@threadsafe</span>
525
+ 385: <span class="ruby-ivar">@object</span> = <span class="ruby-constant">ThreadSafe</span>.<span class="ruby-identifier">new</span> <span class="ruby-ivar">@object</span>
526
+ 386: <span class="ruby-keyword kw">end</span>
527
+ 387:
528
+ 388: <span class="ruby-ivar">@ppid</span>, <span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">ppid</span>, <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">pid</span>
529
+ 389: <span class="ruby-ivar">@socket</span> = <span class="ruby-keyword kw">nil</span>
530
+ 390: <span class="ruby-ivar">@uri</span> = <span class="ruby-keyword kw">nil</span>
531
+ 391:
532
+ 392: <span class="ruby-identifier">tmpdir</span>, <span class="ruby-identifier">basename</span> = <span class="ruby-constant">Dir</span><span class="ruby-operator">::</span><span class="ruby-identifier">tmpdir</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">basename</span>(<span class="ruby-ivar">@psname</span>)
533
+ 393:
534
+ 394: <span class="ruby-ivar">@socket_creation_attempts</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attempt</span><span class="ruby-operator">|</span>
535
+ 395: <span class="ruby-identifier">se</span> = <span class="ruby-keyword kw">nil</span>
536
+ 396: <span class="ruby-keyword kw">begin</span>
537
+ 397: <span class="ruby-identifier">s</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">join</span>(<span class="ruby-identifier">tmpdir</span>, <span class="ruby-node">&quot;#{ basename }_#{ attempt }_#{ rand }&quot;</span>)
538
+ 398: <span class="ruby-identifier">u</span> = <span class="ruby-node">&quot;drbunix://#{ s }&quot;</span>
539
+ 399: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span> <span class="ruby-identifier">u</span>, <span class="ruby-ivar">@object</span>
540
+ 400: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">s</span>
541
+ 401: <span class="ruby-ivar">@uri</span> = <span class="ruby-identifier">u</span>
542
+ 402: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;child - socket &lt;#{ @socket }&gt;&quot;</span> }
543
+ 403: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;child - uri &lt;#{ @uri }&gt;&quot;</span> }
544
+ 404: <span class="ruby-keyword kw">break</span>
545
+ 405: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EADDRINUSE</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">se</span>
546
+ 406: <span class="ruby-keyword kw">nil</span>
547
+ 407: <span class="ruby-keyword kw">end</span>
548
+ 408: <span class="ruby-keyword kw">end</span>
549
+ 409:
550
+ 410: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@uri</span>
551
+ 411: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">'SIGUSR2'</span>) <span class="ruby-keyword kw">do</span>
552
+ 412: <span class="ruby-constant">DBb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>.<span class="ruby-identifier">kill</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
553
+ 413: <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
554
+ 414: <span class="ruby-identifier">exit</span>
555
+ 415: <span class="ruby-keyword kw">end</span>
556
+ 416:
557
+ 417: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">puts</span> <span class="ruby-ivar">@socket</span>
558
+ 418: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">cling</span>
559
+ 419: <span class="ruby-keyword kw">else</span>
560
+ 420: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">release</span>
561
+ 421: <span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;slave(#{ $$ }) could not create socket!&quot;</span>
562
+ 422: <span class="ruby-identifier">exit</span>
563
+ 423: <span class="ruby-keyword kw">end</span>
564
+ 424: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
565
+ 425: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join &quot;\n&quot; }]</span> }
566
+ 426: <span class="ruby-keyword kw">ensure</span>
567
+ 427: <span class="ruby-identifier">status</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'status'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">:</span> <span class="ruby-value">1</span>
568
+ 428: <span class="ruby-identifier">exit</span>(<span class="ruby-identifier">status</span>)
569
+ 429: <span class="ruby-keyword kw">end</span>
570
+ 430: <span class="ruby-comment cmt">#</span>
571
+ 431: <span class="ruby-comment cmt"># parent </span>
572
+ 432: <span class="ruby-comment cmt">#</span>
573
+ 433: <span class="ruby-keyword kw">else</span>
574
+ 434: <span class="ruby-identifier">detach</span>
575
+ 435: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">throw</span>
576
+ 436:
577
+ 437: <span class="ruby-identifier">buf</span> = <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">gets</span>
578
+ 438: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;failed to find slave socket&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">empty?</span>
579
+ 439: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">strip</span>
580
+ 440: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;parent - socket &lt;#{ @socket }&gt;&quot;</span> }
581
+ 441:
582
+ 442: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@at_exit</span>
583
+ 443: <span class="ruby-ivar">@at_exit_thread</span> = <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">on_cut</span>{
584
+ 444: <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'call'</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">send</span>(<span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-keyword kw">self</span>)
585
+ 445: }
586
+ 446: <span class="ruby-keyword kw">end</span>
587
+ 447:
588
+ 448: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">exist?</span> <span class="ruby-ivar">@socket</span>
589
+ 449: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span>{ <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span> }
590
+ 450: <span class="ruby-ivar">@uri</span> = <span class="ruby-node">&quot;drbunix://#{ socket }&quot;</span>
591
+ 451: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;parent - uri &lt;#{ @uri }&gt;&quot;</span> }
592
+ 452: <span class="ruby-comment cmt">#</span>
593
+ 453: <span class="ruby-comment cmt"># starting drb on localhost avoids dns lookups!</span>
594
+ 454: <span class="ruby-comment cmt">#</span>
595
+ 455: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span>(<span class="ruby-value str">'druby://localhost:0'</span>, <span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>
596
+ 456: <span class="ruby-ivar">@object</span> = <span class="ruby-constant">DRbObject</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-ivar">@uri</span>
597
+ 457: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value str">'__slave_object_failure__'</span>
598
+ 458: <span class="ruby-identifier">c</span>, <span class="ruby-identifier">m</span>, <span class="ruby-identifier">bt</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">__slave_object_failure__</span>
599
+ 459: (<span class="ruby-identifier">e</span> = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>)).<span class="ruby-identifier">set_backtrace</span> <span class="ruby-identifier">bt</span>
600
+ 460: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join &quot;\n&quot; }]</span> }
601
+ 461: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
602
+ 462: <span class="ruby-keyword kw">end</span>
603
+ 463: <span class="ruby-ivar">@psname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@object</span>)
604
+ 464: <span class="ruby-keyword kw">else</span>
605
+ 465: <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;failed to find slave socket &lt;#{ @socket }&gt;&quot;</span>
606
+ 466: <span class="ruby-keyword kw">end</span>
607
+ 467: <span class="ruby-keyword kw">end</span>
608
+ 468: <span class="ruby-comment cmt">#--}}}</span>
609
+ 469: <span class="ruby-keyword kw">end</span>
610
+ </pre>
611
+ </div>
612
+ </div>
613
+ </div>
614
+
615
+ <div id="method-M000015" class="method-detail">
616
+ <a name="M000015"></a>
617
+
618
+ <div class="method-heading">
619
+ <a href="#M000015" class="method-signature">
620
+ <span class="method-name">object</span><span class="method-args">opts = {}, &amp;b</span>
621
+ </a>
622
+ </div>
623
+
624
+ <div class="method-description">
625
+ <p>
626
+ a simple convenience method which returns an <b>object</b> from another
627
+ process. the object returned is the result of the supplied block. eg
628
+ </p>
629
+ <pre>
630
+ object = Slave.object{ processor_intensive_object_built_in_child_process() }
631
+ </pre>
632
+ <p>
633
+ eg.
634
+ </p>
635
+ <p>
636
+ the call can be made asynchronous via the &#8216;async&#8217;/:async
637
+ keyword
638
+ </p>
639
+ <pre>
640
+ thread = Slave.object(:async=&gt;true){ long_processor_intensive_object_built_in_child_process() }
641
+
642
+ # go on about your coding business then, later
643
+
644
+ object = thread.value
645
+ </pre>
646
+ <p><a class="source-toggle" href="#"
647
+ onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
648
+ <div class="method-source-code" id="M000015-source">
649
+ <pre>
650
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 589</span>
651
+ 589: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">object</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>
652
+ 590: <span class="ruby-comment cmt">#--{{{</span>
653
+ 591: <span class="ruby-identifier">l</span> = <span class="ruby-identifier">lambda</span>{ <span class="ruby-keyword kw">begin</span>; <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>; <span class="ruby-keyword kw">ensure</span>; <span class="ruby-identifier">exit</span>; <span class="ruby-keyword kw">end</span> }
654
+ 592:
655
+ 593: <span class="ruby-identifier">async</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">'async'</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:async</span>)
656
+ 594:
657
+ 595: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'object'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:object</span>] = <span class="ruby-identifier">l</span>
658
+ 596: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'dumped'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:dumped</span>] = <span class="ruby-keyword kw">true</span>
659
+ 597:
660
+ 598: <span class="ruby-identifier">slave</span> = <span class="ruby-constant">Slave</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">opts</span>
661
+ 599:
662
+ 600: <span class="ruby-identifier">async</span> <span class="ruby-value">? </span><span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">object</span>.<span class="ruby-identifier">call</span> } <span class="ruby-operator">:</span> <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">object</span>.<span class="ruby-identifier">call</span>
663
+ 601: <span class="ruby-comment cmt">#--}}}</span>
664
+ 602: <span class="ruby-keyword kw">end</span>
665
+ </pre>
666
+ </div>
667
+ </div>
668
+ </div>
669
+
670
+ <div id="method-M000016" class="method-detail">
671
+ <a name="M000016"></a>
672
+
673
+ <div class="method-heading">
674
+ <a href="#M000016" class="method-signature">
675
+ <span class="method-name">object</span><span class="method-args">opts = {}, &amp;b</span>
676
+ </a>
677
+ </div>
678
+
679
+ <div class="method-description">
680
+ <p><a class="source-toggle" href="#"
681
+ onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
682
+ <div class="method-source-code" id="M000016-source">
683
+ <pre>
684
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 603</span>
685
+ 603: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">object</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>
686
+ 604: <span class="ruby-comment cmt">#--{{{</span>
687
+ 605: <span class="ruby-identifier">async</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">'async'</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:async</span>)
688
+ 606:
689
+ 607: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'object'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:object</span>] = <span class="ruby-identifier">lambda</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>)
690
+ 608: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'dumped'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:dumped</span>] = <span class="ruby-keyword kw">true</span>
691
+ 609:
692
+ 610: <span class="ruby-identifier">slave</span> = <span class="ruby-constant">Slave</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">opts</span>
693
+ 611:
694
+ 612: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">slave</span><span class="ruby-operator">|</span>
695
+ 613: <span class="ruby-keyword kw">begin</span>
696
+ 614: <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">object</span>.<span class="ruby-identifier">call</span>
697
+ 615: <span class="ruby-keyword kw">ensure</span>
698
+ 616: <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">shutdown</span>
699
+ 617: <span class="ruby-keyword kw">end</span>
700
+ 618: <span class="ruby-keyword kw">end</span>
701
+ 619:
702
+ 620: <span class="ruby-identifier">async</span> <span class="ruby-value">? </span><span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-identifier">value</span>[<span class="ruby-identifier">slave</span>] } <span class="ruby-operator">:</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">slave</span>]
703
+ 621: <span class="ruby-comment cmt">#--}}}</span>
704
+ 622: <span class="ruby-keyword kw">end</span>
576
705
  </pre>
577
706
  </div>
578
707
  </div>
@@ -592,8 +721,8 @@ opts may contain the keys &#8216;object&#8217;,
592
721
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
593
722
  <div class="method-source-code" id="M000001-source">
594
723
  <pre>
595
- <span class="ruby-comment cmt"># File lib/slave.rb, line 40</span>
596
- 40: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version</span>() <span class="ruby-constant">VERSION</span> <span class="ruby-keyword kw">end</span>
724
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 44</span>
725
+ 44: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version</span>() <span class="ruby-constant">VERSION</span> <span class="ruby-keyword kw">end</span>
597
726
  </pre>
598
727
  </div>
599
728
  </div>
@@ -618,12 +747,12 @@ see docs for <a href="Slave.html#M000002">Slave.default</a>
618
747
  onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
619
748
  <div class="method-source-code" id="M000012-source">
620
749
  <pre>
621
- <span class="ruby-comment cmt"># File lib/slave.rb, line 364</span>
622
- 364: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
623
- 365: <span class="ruby-comment cmt">#--{{{</span>
624
- 366: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
625
- 367: <span class="ruby-comment cmt">#--}}}</span>
626
- 368: <span class="ruby-keyword kw">end</span>
750
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 548</span>
751
+ 548: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
752
+ 549: <span class="ruby-comment cmt">#--{{{</span>
753
+ 550: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
754
+ 551: <span class="ruby-comment cmt">#--}}}</span>
755
+ 552: <span class="ruby-keyword kw">end</span>
627
756
  </pre>
628
757
  </div>
629
758
  </div>
@@ -648,33 +777,33 @@ collect the status
648
777
  onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
649
778
  <div class="method-source-code" id="M000006-source">
650
779
  <pre>
651
- <span class="ruby-comment cmt"># File lib/slave.rb, line 291</span>
652
- 291: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">detach</span>
653
- 292: <span class="ruby-comment cmt">#--{{{</span>
654
- 293: <span class="ruby-identifier">reap</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cid</span><span class="ruby-operator">|</span>
655
- 294: <span class="ruby-keyword kw">begin</span>
656
- 295: <span class="ruby-ivar">@status</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">waitpid2</span>(<span class="ruby-identifier">cid</span>).<span class="ruby-identifier">last</span>
657
- 296: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
658
- 297: <span class="ruby-identifier">m</span>, <span class="ruby-identifier">c</span>, <span class="ruby-identifier">b</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>)
659
- 298: <span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;#{ m } (#{ c })\n#{ b }&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECHILD</span>
660
- 299: <span class="ruby-keyword kw">end</span>
661
- 300: <span class="ruby-keyword kw">end</span>
662
- 301:
663
- 302: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span> <span class="ruby-keyword kw">do</span>
664
- 303: <span class="ruby-identifier">shutdown</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
665
- 304: <span class="ruby-identifier">reap</span>[<span class="ruby-ivar">@pid</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
666
- 305: <span class="ruby-keyword kw">end</span>
667
- 306:
668
- 307: <span class="ruby-ivar">@waiter</span> =
669
- 308: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
670
- 309: <span class="ruby-keyword kw">begin</span>
671
- 310: <span class="ruby-ivar">@status</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">waitpid2</span>(<span class="ruby-ivar">@pid</span>).<span class="ruby-identifier">last</span>
672
- 311: <span class="ruby-keyword kw">ensure</span>
673
- 312: <span class="ruby-identifier">reap</span> = <span class="ruby-identifier">lambda</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">cid</span><span class="ruby-operator">|</span> <span class="ruby-value str">'no-op'</span> }
674
- 313: <span class="ruby-keyword kw">end</span>
675
- 314: <span class="ruby-keyword kw">end</span>
676
- 315: <span class="ruby-comment cmt">#--}}}</span>
677
- 316: <span class="ruby-keyword kw">end</span>
780
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 475</span>
781
+ 475: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">detach</span>
782
+ 476: <span class="ruby-comment cmt">#--{{{</span>
783
+ 477: <span class="ruby-identifier">reap</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cid</span><span class="ruby-operator">|</span>
784
+ 478: <span class="ruby-keyword kw">begin</span>
785
+ 479: <span class="ruby-ivar">@status</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">waitpid2</span>(<span class="ruby-identifier">cid</span>).<span class="ruby-identifier">last</span>
786
+ 480: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
787
+ 481: <span class="ruby-identifier">m</span>, <span class="ruby-identifier">c</span>, <span class="ruby-identifier">b</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>)
788
+ 482: <span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;#{ m } (#{ c })\n#{ b }&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECHILD</span>
789
+ 483: <span class="ruby-keyword kw">end</span>
790
+ 484: <span class="ruby-keyword kw">end</span>
791
+ 485:
792
+ 486: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span> <span class="ruby-keyword kw">do</span>
793
+ 487: <span class="ruby-identifier">shutdown</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
794
+ 488: <span class="ruby-identifier">reap</span>[<span class="ruby-ivar">@pid</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
795
+ 489: <span class="ruby-keyword kw">end</span>
796
+ 490:
797
+ 491: <span class="ruby-ivar">@waiter</span> =
798
+ 492: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
799
+ 493: <span class="ruby-keyword kw">begin</span>
800
+ 494: <span class="ruby-ivar">@status</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">waitpid2</span>(<span class="ruby-ivar">@pid</span>).<span class="ruby-identifier">last</span>
801
+ 495: <span class="ruby-keyword kw">ensure</span>
802
+ 496: <span class="ruby-identifier">reap</span> = <span class="ruby-identifier">lambda</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">cid</span><span class="ruby-operator">|</span> <span class="ruby-value str">'no-op'</span> }
803
+ 497: <span class="ruby-keyword kw">end</span>
804
+ 498: <span class="ruby-keyword kw">end</span>
805
+ 499: <span class="ruby-comment cmt">#--}}}</span>
806
+ 500: <span class="ruby-keyword kw">end</span>
678
807
  </pre>
679
808
  </div>
680
809
  </div>
@@ -697,12 +826,12 @@ generate a default name to appear in ps/top
697
826
  onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
698
827
  <div class="method-source-code" id="M000011-source">
699
828
  <pre>
700
- <span class="ruby-comment cmt"># File lib/slave.rb, line 356</span>
701
- 356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gen_psname</span> <span class="ruby-identifier">obj</span>
702
- 357: <span class="ruby-comment cmt">#--{{{</span>
703
- 358: <span class="ruby-node">&quot;#{ obj.class }_#{ obj.object_id }_#{ Process::ppid }_#{ Process::pid }&quot;</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">%/\s+/</span>,<span class="ruby-value str">'_'</span>)
704
- 359: <span class="ruby-comment cmt">#--}}}</span>
705
- 360: <span class="ruby-keyword kw">end</span>
829
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 540</span>
830
+ 540: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gen_psname</span> <span class="ruby-identifier">obj</span>
831
+ 541: <span class="ruby-comment cmt">#--{{{</span>
832
+ 542: <span class="ruby-node">&quot;slave_#{ obj.class }_#{ obj.object_id }_#{ Process::ppid }_#{ Process::pid }&quot;</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">%/\s+/</span>,<span class="ruby-value str">'_'</span>)
833
+ 543: <span class="ruby-comment cmt">#--}}}</span>
834
+ 544: <span class="ruby-keyword kw">end</span>
706
835
  </pre>
707
836
  </div>
708
837
  </div>
@@ -725,12 +854,12 @@ see docs for <a href="Slave.html#M000003">Slave.getopts</a>
725
854
  onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
726
855
  <div class="method-source-code" id="M000013-source">
727
856
  <pre>
728
- <span class="ruby-comment cmt"># File lib/slave.rb, line 372</span>
729
- 372: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
730
- 373: <span class="ruby-comment cmt">#--{{{</span>
731
- 374: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
732
- 375: <span class="ruby-comment cmt">#--}}}</span>
733
- 376: <span class="ruby-keyword kw">end</span>
857
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 556</span>
858
+ 556: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
859
+ 557: <span class="ruby-comment cmt">#--{{{</span>
860
+ 558: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
861
+ 559: <span class="ruby-comment cmt">#--}}}</span>
862
+ 560: <span class="ruby-keyword kw">end</span>
734
863
  </pre>
735
864
  </div>
736
865
  </div>
@@ -747,7 +876,7 @@ see docs for <a href="Slave.html#M000003">Slave.getopts</a>
747
876
 
748
877
  <div class="method-description">
749
878
  <p>
750
- stops the heartbeat thread and kills the child process - give the key
879
+ cuts the lifeline and kills the child process - give the key
751
880
  &#8216;quiet&#8217; to ignore errors shutting down, including having
752
881
  already shutdown
753
882
  </p>
@@ -755,17 +884,17 @@ already shutdown
755
884
  onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
756
885
  <div class="method-source-code" id="M000009-source">
757
886
  <pre>
758
- <span class="ruby-comment cmt"># File lib/slave.rb, line 335</span>
759
- 335: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown</span> <span class="ruby-identifier">opts</span> = {}
760
- 336: <span class="ruby-comment cmt">#--{{{</span>
761
- 337: <span class="ruby-identifier">quiet</span> = <span class="ruby-identifier">getopts</span>(<span class="ruby-identifier">opts</span>)[<span class="ruby-value str">'quiet'</span>]
762
- 338: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;already shutdown&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@shutdown</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">quiet</span>
763
- 339: <span class="ruby-identifier">failure</span> = <span class="ruby-identifier">lambda</span>{ <span class="ruby-identifier">raise</span> <span class="ruby-identifier">$!</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">quiet</span> }
764
- 340: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">stop</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">failure</span>.<span class="ruby-identifier">call</span>
765
- 341: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">kill</span>(<span class="ruby-value str">'SIGUSR2'</span>, <span class="ruby-ivar">@pid</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">failure</span>.<span class="ruby-identifier">call</span>
766
- 342: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">true</span>
767
- 343: <span class="ruby-comment cmt">#--}}}</span>
768
- 344: <span class="ruby-keyword kw">end</span>
887
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 519</span>
888
+ 519: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown</span> <span class="ruby-identifier">opts</span> = {}
889
+ 520: <span class="ruby-comment cmt">#--{{{</span>
890
+ 521: <span class="ruby-identifier">quiet</span> = <span class="ruby-identifier">getopts</span>(<span class="ruby-identifier">opts</span>)[<span class="ruby-value str">'quiet'</span>]
891
+ 522: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;already shutdown&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@shutdown</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">quiet</span>
892
+ 523: <span class="ruby-keyword kw">begin</span>; <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">kill</span> <span class="ruby-value str">'SIGUSR2'</span>, <span class="ruby-ivar">@pid</span>; <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>; <span class="ruby-keyword kw">end</span>
893
+ 524: <span class="ruby-keyword kw">begin</span>; <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">cut</span>; <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>; <span class="ruby-keyword kw">end</span>
894
+ 525: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">quiet</span>
895
+ 526: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">true</span>
896
+ 527: <span class="ruby-comment cmt">#--}}}</span>
897
+ 528: <span class="ruby-keyword kw">end</span>
769
898
  </pre>
770
899
  </div>
771
900
  </div>
@@ -788,12 +917,12 @@ true
788
917
  onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
789
918
  <div class="method-source-code" id="M000010-source">
790
919
  <pre>
791
- <span class="ruby-comment cmt"># File lib/slave.rb, line 348</span>
792
- 348: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown?</span>
793
- 349: <span class="ruby-comment cmt">#--{{{</span>
794
- 350: <span class="ruby-ivar">@shutdown</span>
795
- 351: <span class="ruby-comment cmt">#--}}}</span>
796
- 352: <span class="ruby-keyword kw">end</span>
920
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 532</span>
921
+ 532: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown?</span>
922
+ 533: <span class="ruby-comment cmt">#--{{{</span>
923
+ 534: <span class="ruby-ivar">@shutdown</span>
924
+ 535: <span class="ruby-comment cmt">#--}}}</span>
925
+ 536: <span class="ruby-keyword kw">end</span>
797
926
  </pre>
798
927
  </div>
799
928
  </div>
@@ -816,12 +945,15 @@ debugging output - ENV[&#8216;SLAVE_DEBUG&#8217;]=1 to enable
816
945
  onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
817
946
  <div class="method-source-code" id="M000014-source">
818
947
  <pre>
819
- <span class="ruby-comment cmt"># File lib/slave.rb, line 380</span>
820
- 380: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">trace</span>
821
- 381: <span class="ruby-comment cmt">#--{{{</span>
822
- 382: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-keyword kw">yield</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@debug</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">tty?</span>
823
- 383: <span class="ruby-comment cmt">#--}}}</span>
824
- 384: <span class="ruby-keyword kw">end</span>
948
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 564</span>
949
+ 564: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">trace</span>
950
+ 565: <span class="ruby-comment cmt">#--{{{</span>
951
+ 566: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@debug</span>
952
+ 567: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-keyword kw">yield</span>
953
+ 568: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">flush</span>
954
+ 569: <span class="ruby-keyword kw">end</span>
955
+ 570: <span class="ruby-comment cmt">#--}}}</span>
956
+ 571: <span class="ruby-keyword kw">end</span>
825
957
  </pre>
826
958
  </div>
827
959
  </div>
@@ -848,14 +980,14 @@ is given a thread is returned to do the waiting in an async fashion. eg
848
980
  onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
849
981
  <div class="method-source-code" id="M000007-source">
850
982
  <pre>
851
- <span class="ruby-comment cmt"># File lib/slave.rb, line 323</span>
852
- 323: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>
853
- 324: <span class="ruby-comment cmt">#--{{{</span>
854
- 325: <span class="ruby-identifier">b</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">lambda</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">exit_status</span><span class="ruby-operator">|</span>}
855
- 326: <span class="ruby-identifier">non_block</span> = <span class="ruby-identifier">getopts</span>(<span class="ruby-identifier">opts</span>)[<span class="ruby-value str">'non_block'</span>]
856
- 327: <span class="ruby-identifier">non_block</span> <span class="ruby-value">? </span><span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-identifier">b</span>[ <span class="ruby-ivar">@waiter</span>.<span class="ruby-identifier">value</span> ] } <span class="ruby-operator">:</span> <span class="ruby-identifier">b</span>[ <span class="ruby-ivar">@waiter</span>.<span class="ruby-identifier">value</span> ]
857
- 328: <span class="ruby-comment cmt">#--}}}</span>
858
- 329: <span class="ruby-keyword kw">end</span>
983
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 507</span>
984
+ 507: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>
985
+ 508: <span class="ruby-comment cmt">#--{{{</span>
986
+ 509: <span class="ruby-identifier">b</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">lambda</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">exit_status</span><span class="ruby-operator">|</span>}
987
+ 510: <span class="ruby-identifier">non_block</span> = <span class="ruby-identifier">getopts</span>(<span class="ruby-identifier">opts</span>)[<span class="ruby-value str">'non_block'</span>]
988
+ 511: <span class="ruby-identifier">non_block</span> <span class="ruby-value">? </span><span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-identifier">b</span>[ <span class="ruby-ivar">@waiter</span>.<span class="ruby-identifier">value</span> ] } <span class="ruby-operator">:</span> <span class="ruby-identifier">b</span>[ <span class="ruby-ivar">@waiter</span>.<span class="ruby-identifier">value</span> ]
989
+ 512: <span class="ruby-comment cmt">#--}}}</span>
990
+ 513: <span class="ruby-keyword kw">end</span>
859
991
  </pre>
860
992
  </div>
861
993
  </div>