<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>229824</bug_id>
          
          <creation_ts>2021-09-02 12:42:43 -0700</creation_ts>
          <short_desc>[webkitpy] WrappedPopen breaks process returncode</short_desc>
          <delta_ts>2021-09-02 14:10:31 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Tools / Tests</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=201826</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=229758</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Carlos Alberto Lopez Perez">clopez</reporter>
          <assigned_to name="Jonathan Bedard">jbedard</assigned_to>
          <cc>ews-watchlist</cc>
    
    <cc>glenn</cc>
    
    <cc>jbedard</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1789846</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2021-09-02 12:42:43 -0700</bug_when>
    <thetext>The class WrappedPopen() was added in r250375 to wrap the subprocess.Popen() for making the python2 subprocess.Popen() objects more similar to the ones from python3.

But the way this class wraps the objects makes breaks the process returncode if the process doesn&apos;t return immediately.

This is because WrappedPopen() defines a new class the sets functions with the same name than subprocess.Popen() setting the value returned to the one that returns subprocess.Popen().
But in the case of subprocess.Popen().returncode that is not a function, but a string that will change of value when the process ends. If we evaluate this function before we call subprocess.Popen().communicate() or subprocess.Popen().wait() then the value of returncode will be None

This can be checked with this following test program: http://sprunge.us/aoxZ0j

If you run it with python2 you get &quot;The call return code is None&quot; instead of getting &quot;The call return code is 2&quot; which is what it should be (what happens when you run it with python3 which don&apos;t triggers the call to use WrappedPopen())

I have observed this when working on bug 229758 .. with python2 the call from host.executive.popen() always returned a returncode of None

This is not an issue for subprocess.Popen().stdout and subprocess.Popen().stderr because if you look at what prints the debug function on that example for this cases it sets the value to a descriptor rather than reading from the descriptor. So when the call to read from the descriptor is done it will work. Example, you see this:

setting attribute .. stdout to &lt;open file &apos;&lt;fdopen&gt;&apos;, mode &apos;rb&apos; at 0x7fe12cc1d540&gt;
setting attribute .. returncode to None</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789850</commentid>
    <comment_count>1</comment_count>
      <attachid>437186</attachid>
    <who name="Jonathan Bedard">jbedard</who>
    <bug_when>2021-09-02 12:55:48 -0700</bug_when>
    <thetext>Created attachment 437186
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789851</commentid>
    <comment_count>2</comment_count>
    <who name="Jonathan Bedard">jbedard</who>
    <bug_when>2021-09-02 12:56:37 -0700</bug_when>
    <thetext>(In reply to Jonathan Bedard from comment #1)
&gt; Created attachment 437186 [details]
&gt; Patch

I suspect this will fix the problem, although I&apos;m a bit unclear which script can cause this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789864</commentid>
    <comment_count>3</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2021-09-02 13:25:20 -0700</bug_when>
    <thetext>This fixes it indeed, thanks.

I was trying here to instead of wrapping the object to add the __exit__ and __enter__ methods to the Popen class directly, but for some unknown reason then when you try to use the usual &quot;with popen_object:&quot; it doesn&apos;t like this methods added via setattr() and complains about missing __exit__</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789885</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2021-09-02 14:09:22 -0700</bug_when>
    <thetext>Committed r281952 (241259@main): &lt;https://commits.webkit.org/241259@main&gt;

All reviewed patches have been landed. Closing bug and clearing flags on attachment 437186.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1789888</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-09-02 14:10:31 -0700</bug_when>
    <thetext>&lt;rdar://problem/82692759&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>437186</attachid>
            <date>2021-09-02 12:55:48 -0700</date>
            <delta_ts>2021-09-02 14:09:22 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-229824-20210902125548.patch</filename>
            <type>text/plain</type>
            <size>1711</size>
            <attacher name="Jonathan Bedard">jbedard</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjgxOTQ3CmRpZmYgLS1naXQgYS9Ub29scy9DaGFuZ2VMb2cg
Yi9Ub29scy9DaGFuZ2VMb2cKaW5kZXggY2Q5OGJjYmM5NTVmZjhhNGUyM2U1MTlkNTk1Y2M5NTc5
MWI5MDA2YS4uOWUyN2U3ODZhNzA2YmRkZmM3NWNlNTRlNDNlNTBjZWExYmU3MmE1MyAxMDA2NDQK
LS0tIGEvVG9vbHMvQ2hhbmdlTG9nCisrKyBiL1Rvb2xzL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE0
IEBACisyMDIxLTA5LTAyICBKb25hdGhhbiBCZWRhcmQgIDxqYmVkYXJkQGFwcGxlLmNvbT4KKwor
ICAgICAgICBbd2Via2l0cHldIFdyYXBwZWRQb3BlbiBicmVha3MgcHJvY2VzcyByZXR1cm5jb2Rl
C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lbihvYmplY3QpOgogICAgIGRlZiBfX2luaXRfXyhzZWxmLCBwb3Blbik6Ci0gICAgICAg
IGZvciBhdHRyaWJ1dGUgaW4gZGlyKHBvcGVuKToKLSAgICAgICAgICAgIGlmIGF0dHJpYnV0ZS5z
dGFydHN3aXRoKCdfXycpOgorICAgICAgICBzZWxmLl9wb3BlbiA9IHBvcGVuCisgICAgICAgIGZv
ciBhdHRyaWJ1dGUgaW4gZGlyKHNlbGYuX3BvcGVuKToKKyAgICAgICAgICAgIGlmIGF0dHJpYnV0
ZS5zdGFydHN3aXRoKCdfXycpIG9yIGF0dHJpYnV0ZSA9PSAncmV0dXJuY29kZSc6CiAgICAgICAg
ICAgICAgICAgY29udGludWUKLSAgICAgICAgICAgIHNldGF0dHIoc2VsZiwgYXR0cmlidXRlLCBn
ZXRhdHRyKHBvcGVuLCBhdHRyaWJ1dGUpKQorICAgICAgICAgICAgc2V0YXR0cihzZWxmLCBhdHRy
aWJ1dGUsIGdldGF0dHIoc2VsZi5fcG9wZW4sIGF0dHJpYnV0ZSkpCisKKyAgICBAcHJvcGVydHkK
KyAgICBkZWYgcmV0dXJuY29kZShzZWxmKToKKyAgICAgICAgcmV0dXJuIHNlbGYuX3BvcGVuLnJl
dHVybmNvZGUKIAogICAgIGRlZiBfX2VudGVyX18oc2VsZik6CiAgICAgICAgIHJldHVybiBzZWxm
Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>