https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112020-12-05T12:53:42ZRuby Issue Tracking SystemRuby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=889292020-12-05T12:53:42ZEregon (Benoit Daloze)
<ul></ul><p>Does such code still work, with a scheduler?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="sb">`echo foo`</span>
<span class="nb">p</span> <span class="vg">$?</span> <span class="c1"># => #<Process::Status: pid 43525 exit 0></span>
</code></pre>
<p>If not, it seems a significant problem, as existing code would break with a scheduler.</p>
<p>Given the implementation in the test scheduler:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"> <span class="k">def</span> <span class="nf">process_wait</span><span class="p">(</span><span class="n">pid</span><span class="p">,</span> <span class="n">flags</span><span class="p">)</span>
<span class="c1"># This is a very simple way to implement a non-blocking wait:</span>
<span class="no">Thread</span><span class="p">.</span><span class="nf">new</span> <span class="k">do</span>
<span class="no">Process</span><span class="o">::</span><span class="no">Status</span><span class="p">.</span><span class="nf">wait</span><span class="p">(</span><span class="n">pid</span><span class="p">,</span> <span class="n">flags</span><span class="p">)</span>
<span class="k">end</span><span class="p">.</span><span class="nf">join</span>
<span class="k">end</span>
</code></pre>
<p>It sounds like you would need a way to set <code>$?</code> on the current Thread.<br>
So that <code>$?</code> can be set for the caller.<br>
I think that's fine to add.</p>
<p>I think <code>$?</code> should be Fiber-local, probably it's thread-local only for historic reasons.<br>
Otherwise, just switching between Fibers (e.g., on IO) would expose the <code>$?</code> of other Fibers, which will lead to bugs.<br>
I expect that change to cause extremely few compatibility issues (<code>$~</code>, etc are already fiber-local + frame-local).</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=889302020-12-05T12:57:16Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><blockquote>
<p>Does such code still work, with a scheduler?</p>
</blockquote>
<p>Yes.</p>
<blockquote>
<p>It sounds like you would need a way to set $? on the current Thread.</p>
</blockquote>
<p>Nope, it's handled by <code>Process.wait</code> and so on.</p>
<blockquote>
<p>Otherwise, just switching between Fibers (e.g., on IO) would expose the $? of other Fibers, which will lead to bugs.</p>
</blockquote>
<p>Agree, but we can't change this without potentially breaking existing code.</p>
<p>Also, is it okay that <code>Process.last_status</code> and <code>Process.last_status=</code> (hypothetical) are fiber local? Because Matz already said he was against class attributes that are actually fiber local (even if I agree in theory, excluding the fact that this is a breaking change).</p>
<blockquote>
<p>I expect that change to cause extremely few compatibility issues ($~, etc are already fiber-local + frame-local).</p>
</blockquote>
<p>Great, if Matz can approve the change, then we can implement it, but it's separate from this PR, since this PR just makes the existing interface non-blocking.</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=889312020-12-05T13:22:34ZEregon (Benoit Daloze)
<ul></ul><p>I clarified with <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/3344">@ioquatix (Samuel Williams)</a>, the code above should be <code> end.value</code> so it returns the Process::Status and <code>system</code> still sets it.<br>
Then the change sounds good to me.</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=889382020-12-06T06:40:45Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88938/diff?detail_id=58463">diff</a>)</li></ul> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=890152020-12-08T20:19:23Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>Non-blocking <code>Process.wait</code> has been merged.</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=890322020-12-09T08:40:03Znaruse (Yui NARUSE)naruse@airemix.jp
<ul></ul><p>Is this feature discussed with ko1 and nobu?<br>
Also I suspect Matz's approval is required for this change.</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=890662020-12-10T06:08:57Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I am OK with <code>Process::Status.wait</code>. As far as I've heard the code quality needs upgrade.</p>
<p>Matz.</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=890812020-12-10T08:40:18Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> set to <i>3.0</i></li></ul> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=895222020-12-25T02:43:31Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> deleted (<del><i>3.0</i></del>)</li></ul> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=895292020-12-26T07:40:36Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>We introduced experimental feature and implemented non-blocking hook for Ruby 3.</p>
<p>More work is required here, but we didn't make it in time for Ruby 3.0 - so we marked it as experimental.</p>
<p>We also need to implement <code>rb_f_system</code> in terms of <code>rb_process_status_wait</code>. Can someone else help with this?</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=903002021-02-09T21:07:39Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li><li><strong>Backport</strong> deleted (<del><i>2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN</i></del>)</li></ul> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=926162021-06-22T11:46:07Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>See <a href="https://github.com/ruby/ruby/pull/4595" class="external">https://github.com/ruby/ruby/pull/4595</a> which implements non-blocking <code>Kernel#system</code>.</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=938822021-09-27T04:01:32Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>The implementation is completed.</p>
<p>However, some parts are still pretty messy, including leaking <code>$?</code> process status.</p>
<p>We need to make <code>$?</code> fiber local.</p>
<pre><code>irb(main):012:0> Fiber.new{system("false")}.resume; pp $?
#<Process::Status: pid 628235 exit 1>
=> #<Process::Status: pid 628235 exit 1>
irb(main):013:0> Fiber.new{system("true")}.resume; pp $?
#<Process::Status: pid 628241 exit 0>
=> #<Process::Status: pid 628241 exit 0>
</code></pre>
<p>However this might cause some issues in existing code.</p>
<p>Should we consider to deprecate <code>$?</code>?</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=941052021-10-11T17:48:28ZEregon (Benoit Daloze)
<ul></ul><p>I think making <code>$?</code> Fiber-local makes sense, and unlikely to break anything.<br>
I don't see the need to deprecate <code>$?</code>, and it's certainly not worth the cost to migrate existing code to some other way to the get the status.</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=942162021-10-21T07:49:50Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Please file a new issue for fiber-local <code>$?</code>.</p> Ruby master - Feature #17369: Introduce non-blocking `Process.wait`, `Kernel.system` and related methods.https://bugs.ruby-lang.org/issues/17369?journal_id=942172021-10-21T07:50:20Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul>