You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a weird thing about subprocess.Popen ... it has a separate .returncode attribute and .poll() method. Calling .poll() checks if the process has finished, and if so, it returns the value, and it also updates .returncode as a side-effect. .returncode OTOH is totally passive; it returns stale data until you explicitly call .poll() or .wait().
In this case, __repr__ here is using .returncode, so it can show stale data. The other option would be to use .poll(), so it would return up-to-date data... but then this would also mutate the .returncode attribute as a side-effect, and you usually don't want __repr__ to mutate anything.
So I sort of think we should instead fix .returncode, so that it's always up-to-date:
@propertydefreturncode(self):
returnself.poll()
And then __repr__ would show up-to-date information, and wouldn't have any user-visible mutation effects.
Activity
njsmith commentedon Nov 22, 2019
This is a weird thing about
subprocess.Popen... it has a separate.returncodeattribute and.poll()method. Calling.poll()checks if the process has finished, and if so, it returns the value, and it also updates.returncodeas a side-effect..returncodeOTOH is totally passive; it returns stale data until you explicitly call.poll()or.wait().In this case,
__repr__here is using.returncode, so it can show stale data. The other option would be to use.poll(), so it would return up-to-date data... but then this would also mutate the.returncodeattribute as a side-effect, and you usually don't want__repr__to mutate anything.So I sort of think we should instead fix
.returncode, so that it's always up-to-date:And then
__repr__would show up-to-date information, and wouldn't have any user-visible mutation effects.