Myoldmopar/decent_ci

View on GitHub
docs/Runners.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
  Module: Runners
  
    &mdash; Documentation by YARD 0.9.19
  
</title>

  <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  pathId = "Runners";
  relpath = '';
</script>


  <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="js/app.js"></script>


  </head>
  <body>
    <div class="nav_wrap">
      <iframe id="nav" src="class_list.html?1"></iframe>
      <div id="resizer"></div>
    </div>

    <div id="main" tabindex="-1">
      <div id="header">
        <div id="menu">
  
    <a href="_index.html">Index (R)</a> &raquo;
    
    
    <span class="title">Runners</span>
  
</div>

        <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="class_list.html">

        <svg width="24" height="24">
          <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
        </svg>
    </a>
  
</div>
        <div class="clear"></div>
      </div>

      <div id="content"><h1>Module: Runners
  
  
  
</h1>
<div class="box_info">
  

  
  
  
  
  

  
  <dl>
    <dt>Included in:</dt>
    <dd><span class='object_link'><a href="CMake.html" title="CMake (module)">CMake</a></span>, <span class='object_link'><a href="Lcov.html" title="Lcov (module)">Lcov</a></span>, <span class='object_link'><a href="PotentialBuild.html" title="PotentialBuild (class)">PotentialBuild</a></span></dd>
  </dl>
  

  
  <dl>
    <dt>Defined in:</dt>
    <dd>lib/runners.rb</dd>
  </dl>
  
</div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    
<p>captures functions to run commands on the system</p>


  </div>
</div>
<div class="tags">
  

</div>






  
    <h2>
      Instance Method Summary
      <small><a href="#" class="summary_toggle">collapse</a></small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#monitor_thread_state-instance_method" title="#monitor_thread_state (instance method)">#<strong>monitor_thread_state</strong>(timeout, thread, tick, stdout, stderr)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#read_state_singular-instance_method" title="#read_state_singular (instance method)">#<strong>read_state_singular</strong>(stdout, stderr, tick, out, err)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#run_scripts-instance_method" title="#run_scripts (instance method)">#<strong>run_scripts</strong>(this_config, commands, env = {})  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#run_single_script-instance_method" title="#run_single_script (instance method)">#<strong>run_single_script</strong>(this_config, cmd, env)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#run_with_timeout-instance_method" title="#run_with_timeout (instance method)">#<strong>run_with_timeout</strong>(env, command, timeout = 60 * 60 * 4, tick = 2)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>originally from <a href="https://gist.github.com/lpar/1032297">gist.github.com/lpar/1032297</a> runs a specified shell command in a separate thread.</p>
</div></span>
  
</li>

      
    </ul>
  



  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="monitor_thread_state-instance_method">
  
    #<strong>monitor_thread_state</strong>(timeout, thread, tick, stdout, stderr)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/runners.rb', line 66</span>

<span class='kw'>def</span> <span class='id identifier rubyid_monitor_thread_state'>monitor_thread_state</span><span class='lparen'>(</span><span class='id identifier rubyid_timeout'>timeout</span><span class='comma'>,</span> <span class='id identifier rubyid_thread'>thread</span><span class='comma'>,</span> <span class='id identifier rubyid_tick'>tick</span><span class='comma'>,</span> <span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_pid'>pid</span> <span class='op'>=</span> <span class='id identifier rubyid_thread'>thread</span><span class='lbracket'>[</span><span class='symbol'>:pid</span><span class='rbracket'>]</span>
  <span class='id identifier rubyid_start'>start</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span>
  <span class='id identifier rubyid_out'>out</span> <span class='op'>=</span> <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='comment'># rubocop:disable Performance/UnfreezeString:
</span>  <span class='id identifier rubyid_err'>err</span> <span class='op'>=</span> <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='comment'># rubocop:disable Performance/UnfreezeString:
</span>  <span class='kw'>while</span> <span class='lparen'>(</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span> <span class='op'>-</span> <span class='id identifier rubyid_start'>start</span><span class='rparen'>)</span> <span class='op'>&lt;</span> <span class='id identifier rubyid_timeout'>timeout</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_thread'>thread</span><span class='period'>.</span><span class='id identifier rubyid_alive?'>alive?</span>
    <span class='id identifier rubyid_out'>out</span><span class='comma'>,</span> <span class='id identifier rubyid_err'>err</span><span class='comma'>,</span> <span class='id identifier rubyid_this_break'>this_break</span> <span class='op'>=</span> <span class='id identifier rubyid_read_state_singular'>read_state_singular</span><span class='lparen'>(</span><span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='comma'>,</span> <span class='id identifier rubyid_tick'>tick</span><span class='comma'>,</span> <span class='id identifier rubyid_out'>out</span><span class='comma'>,</span> <span class='id identifier rubyid_err'>err</span><span class='rparen'>)</span>
    <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_this_break'>this_break</span>
  <span class='kw'>end</span>

  <span class='comment'># Give Ruby time to clean up the other thread
</span>  <span class='id identifier rubyid_sleep'>sleep</span> <span class='int'>1</span>

  <span class='kw'>if</span> <span class='id identifier rubyid_thread'>thread</span><span class='period'>.</span><span class='id identifier rubyid_alive?'>alive?</span>    <span class='comment'># We need to kill the process, because killing the thread leaves
</span>    <span class='comment'># the process alive but detached, annoyingly enough.
</span>    <span class='comment'># :nocov: I cannot figure out how to reproduce this right now
</span>
    <span class='const'>Process</span><span class='period'>.</span><span class='id identifier rubyid_kill'>kill</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>TERM</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_pid'>pid</span><span class='rparen'>)</span>    <span class='comment'># :nocov:
</span>
  <span class='kw'>end</span>
  <span class='lbracket'>[</span><span class='id identifier rubyid_out'>out</span><span class='comma'>,</span> <span class='id identifier rubyid_err'>err</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="read_state_singular-instance_method">
  
    #<strong>read_state_singular</strong>(stdout, stderr, tick, out, err)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/runners.rb', line 89</span>

<span class='kw'>def</span> <span class='id identifier rubyid_read_state_singular'>read_state_singular</span><span class='lparen'>(</span><span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='comma'>,</span> <span class='id identifier rubyid_tick'>tick</span><span class='comma'>,</span> <span class='id identifier rubyid_out'>out</span><span class='comma'>,</span> <span class='id identifier rubyid_err'>err</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_this_break'>this_break</span> <span class='op'>=</span> <span class='kw'>false</span>  <span class='comment'># Wait up to `tick` seconds for output/error data
</span>
  <span class='id identifier rubyid_rs'>rs</span><span class='comma'>,</span> <span class='op'>=</span> <span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_tick'>tick</span><span class='rparen'>)</span>  <span class='comment'># Try to read the data
</span>
  <span class='kw'>begin</span>
    <span class='id identifier rubyid_rs'>rs</span><span class='op'>&amp;.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_r'>r</span><span class='op'>|</span>
      <span class='kw'>if</span> <span class='id identifier rubyid_r'>r</span> <span class='op'>==</span> <span class='id identifier rubyid_stdout'>stdout</span>
        <span class='id identifier rubyid_out'>out</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_stdout'>stdout</span><span class='period'>.</span><span class='id identifier rubyid_read_nonblock'>read_nonblock</span><span class='lparen'>(</span><span class='int'>4096</span><span class='rparen'>)</span>
      <span class='kw'>elsif</span> <span class='id identifier rubyid_r'>r</span> <span class='op'>==</span> <span class='id identifier rubyid_stderr'>stderr</span>
        <span class='id identifier rubyid_err'>err</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='period'>.</span><span class='id identifier rubyid_read_nonblock'>read_nonblock</span><span class='lparen'>(</span><span class='int'>4096</span><span class='rparen'>)</span>
      <span class='kw'>end</span>
    <span class='kw'>end</span>
  <span class='kw'>rescue</span> <span class='const'>IO</span><span class='op'>::</span><span class='const'>WaitReadable</span> <span class='comment'># rubocop:disable Lint/SuppressedException
</span>    <span class='comment'># A read would block, so loop around for another select
</span>  <span class='kw'>rescue</span> <span class='const'>EOFError</span>    <span class='comment'># Command has completed, not really an error...
</span>
    <span class='id identifier rubyid_this_break'>this_break</span> <span class='op'>=</span> <span class='kw'>true</span>
  <span class='kw'>end</span>
  <span class='lbracket'>[</span><span class='id identifier rubyid_out'>out</span><span class='comma'>,</span> <span class='id identifier rubyid_err'>err</span><span class='comma'>,</span> <span class='id identifier rubyid_this_break'>this_break</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="run_scripts-instance_method">
  
    #<strong>run_scripts</strong>(this_config, commands, env = {})  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/runners.rb', line 7</span>

<span class='kw'>def</span> <span class='id identifier rubyid_run_scripts'>run_scripts</span><span class='lparen'>(</span><span class='id identifier rubyid_this_config'>this_config</span><span class='comma'>,</span> <span class='id identifier rubyid_commands'>commands</span><span class='comma'>,</span> <span class='id identifier rubyid_env'>env</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_all_out'>all_out</span> <span class='op'>=</span> <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='comment'># rubocop:disable Performance/UnfreezeString: Too much burden to unfreeze everywhere
</span>  <span class='id identifier rubyid_all_err'>all_err</span> <span class='op'>=</span> <span class='const'>String</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='comment'># rubocop:disable Performance/UnfreezeString:
</span>  <span class='id identifier rubyid_all_result'>all_result</span> <span class='op'>=</span> <span class='int'>0</span>

  <span class='id identifier rubyid_commands'>commands</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_cmd'>cmd</span><span class='op'>|</span>
    <span class='id identifier rubyid_out_this_cmd'>out_this_cmd</span><span class='comma'>,</span> <span class='id identifier rubyid_err_this_cmd'>err_this_cmd</span><span class='comma'>,</span> <span class='id identifier rubyid_result_this_command'>result_this_command</span> <span class='op'>=</span> <span class='id identifier rubyid_run_single_script'>run_single_script</span><span class='lparen'>(</span><span class='id identifier rubyid_this_config'>this_config</span><span class='comma'>,</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='comma'>,</span> <span class='id identifier rubyid_env'>env</span><span class='rparen'>)</span>

    <span class='gvar'>$logger</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Error running script command: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_cmd'>cmd</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_result_this_command'>result_this_command</span><span class='period'>.</span><span class='id identifier rubyid_exitstatus'>exitstatus</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span>

    <span class='id identifier rubyid_all_out'>all_out</span> <span class='op'>+=</span> <span class='id identifier rubyid_out_this_cmd'>out_this_cmd</span>
    <span class='id identifier rubyid_all_err'>all_err</span> <span class='op'>+=</span> <span class='id identifier rubyid_err_this_cmd'>err_this_cmd</span>
    <span class='id identifier rubyid_all_result'>all_result</span> <span class='op'>+=</span> <span class='id identifier rubyid_result_this_command'>result_this_command</span><span class='period'>.</span><span class='id identifier rubyid_exitstatus'>exitstatus</span>
  <span class='kw'>end</span>

  <span class='lbracket'>[</span><span class='id identifier rubyid_all_out'>all_out</span><span class='comma'>,</span> <span class='id identifier rubyid_all_err'>all_err</span><span class='comma'>,</span> <span class='id identifier rubyid_all_result'>all_result</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="run_single_script-instance_method">
  
    #<strong>run_single_script</strong>(this_config, cmd, env)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/runners.rb', line 25</span>

<span class='kw'>def</span> <span class='id identifier rubyid_run_single_script'>run_single_script</span><span class='lparen'>(</span><span class='id identifier rubyid_this_config'>this_config</span><span class='comma'>,</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='comma'>,</span> <span class='id identifier rubyid_env'>env</span><span class='rparen'>)</span>
  <span class='kw'>if</span> <span class='id identifier rubyid_this_config'>this_config</span><span class='period'>.</span><span class='id identifier rubyid_os'>os</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Windows</span><span class='tstring_end'>&#39;</span></span>    <span class='comment'># :nocov: Not testing on Windows
</span>
    <span class='gvar'>$logger</span><span class='period'>.</span><span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Unable to set timeout for process execution on windows</span><span class='tstring_end'>&#39;</span></span>
    <span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='comma'>,</span> <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>Open3</span><span class='period'>.</span><span class='id identifier rubyid_capture3'>capture3</span><span class='lparen'>(</span><span class='id identifier rubyid_env'>env</span><span class='comma'>,</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>    <span class='comment'># :nocov:
</span>
  <span class='kw'>else</span>
    <span class='comment'># allow up to 6 hours
</span>    <span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='comma'>,</span> <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_run_with_timeout'>run_with_timeout</span><span class='lparen'>(</span><span class='id identifier rubyid_env'>env</span><span class='comma'>,</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='comma'>,</span> <span class='int'>60</span> <span class='op'>*</span> <span class='int'>60</span> <span class='op'>*</span> <span class='int'>6</span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='id identifier rubyid_stderr'>stderr</span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>UTF-8</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='symbol'>:invalid</span> <span class='op'>=&gt;</span> <span class='symbol'>:replace</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\n</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_l'>l</span><span class='op'>|</span>
    <span class='gvar'>$logger</span><span class='period'>.</span><span class='id identifier rubyid_debug'>debug</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>cmd: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_cmd'>cmd</span><span class='embexpr_end'>}</span><span class='tstring_content'>: stderr: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_l'>l</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='lbracket'>[</span><span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='comma'>,</span> <span class='id identifier rubyid_result'>result</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="run_with_timeout-instance_method">
  
    #<strong>run_with_timeout</strong>(env, command, timeout = 60 * 60 * 4, tick = 2)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>originally from <a href="https://gist.github.com/lpar/1032297">gist.github.com/lpar/1032297</a> runs a specified shell command in a separate thread. If it exceeds the given timeout in seconds, kills it. Returns any output produced by the command (stdout or stderr) as a String. Uses Kernel.select to wait up to the tick length (in seconds) between checks on the command&#39;s status</p>

<p>If you&#39;ve got a cleaner way of doing this, I&#39;d be interested to see it. If you think you can do it with Ruby&#39;s Timeout module, think again.</p>


  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


52
53
54
55
56
57
58
59
60
61
62
63
64</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/runners.rb', line 52</span>

<span class='kw'>def</span> <span class='id identifier rubyid_run_with_timeout'>run_with_timeout</span><span class='lparen'>(</span><span class='id identifier rubyid_env'>env</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_timeout'>timeout</span> <span class='op'>=</span> <span class='int'>60</span> <span class='op'>*</span> <span class='int'>60</span> <span class='op'>*</span> <span class='int'>4</span><span class='comma'>,</span> <span class='id identifier rubyid_tick'>tick</span> <span class='op'>=</span> <span class='int'>2</span><span class='rparen'>)</span>
  <span class='kw'>begin</span>
    <span class='comment'># Start task in another thread, which spawns a process
</span>    <span class='id identifier rubyid_stdin'>stdin</span><span class='comma'>,</span> <span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='comma'>,</span> <span class='id identifier rubyid_thread'>thread</span> <span class='op'>=</span> <span class='const'>Open3</span><span class='period'>.</span><span class='id identifier rubyid_popen3'>popen3</span><span class='lparen'>(</span><span class='id identifier rubyid_env'>env</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>    <span class='comment'># Start watching the original running thread and watching output
</span>
    <span class='id identifier rubyid_out'>out</span><span class='comma'>,</span> <span class='id identifier rubyid_err'>err</span> <span class='op'>=</span> <span class='id identifier rubyid_monitor_thread_state'>monitor_thread_state</span><span class='lparen'>(</span><span class='id identifier rubyid_timeout'>timeout</span><span class='comma'>,</span> <span class='id identifier rubyid_thread'>thread</span><span class='comma'>,</span> <span class='id identifier rubyid_tick'>tick</span><span class='comma'>,</span> <span class='id identifier rubyid_stdout'>stdout</span><span class='comma'>,</span> <span class='id identifier rubyid_stderr'>stderr</span><span class='rparen'>)</span>
  <span class='kw'>ensure</span>
    <span class='id identifier rubyid_stdin'>stdin</span><span class='op'>&amp;.</span><span class='id identifier rubyid_close'>close</span>
    <span class='id identifier rubyid_stdout'>stdout</span><span class='op'>&amp;.</span><span class='id identifier rubyid_close'>close</span>
    <span class='id identifier rubyid_stderr'>stderr</span><span class='op'>&amp;.</span><span class='id identifier rubyid_close'>close</span>
  <span class='kw'>end</span>
  <span class='lbracket'>[</span><span class='id identifier rubyid_out'>out</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>UTF-8</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_err'>err</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>UTF-8</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_thread'>thread</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

      <div id="footer">
  Generated on Thu May 18 10:34:59 2023 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.9.19 (ruby-2.7.0).
</div>

    </div>
  </body>
</html>