This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Implement subprocess.Popen.__repr__
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jason.Killen, cool-RR, gregory.p.smith, mdebi, pitrou, rhettinger, taleinat
Priority: normal Keywords: easy, patch

Created on 2019-11-06 19:44 by cool-RR, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17151 merged python-dev, 2019-11-14 10:30
Messages (8)
msg356149 - (view) Author: Ram Rachum (cool-RR) * Date: 2019-11-06 19:44
I was working with a Popen object recently in the shell and it was annoying to see the `<subprocess.Popen at 0x4f83898>` display. It would be nice to get some kind of minimal detail about the Popen, for example its args and return code, if finished.
msg356550 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-11-13 19:48
I agree that this could be nice. A PR (with tests!) would be welcome!
msg356561 - (view) Author: Jason Killen (Jason.Killen) * Date: 2019-11-13 21:57
I think this sounds great and I'll take a crack at it over the next few days.  If anybody wants to jump ahead of me I don't mind.
msg356564 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-11-13 22:27
+1 for a more informative repr (like we did with regex match objects).

There are a lot of parameters to subprocess.Popen().  RR is on the right track suggesting that only a small, useful subset of those be included:  args and the return code.  

We could add the *pid* argument as well, but may be no more useful or attractive than the current repr's object id.

The repr should be enclosed in angle brackets because it can't recreate the object.
msg356576 - (view) Author: Debi Mishra (mdebi) * Date: 2019-11-14 05:04
Hi @Jason.Killen. I am new to cpython and would like to try this one out. Thank you.
msg356598 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-11-14 11:22
I agree with Raymond, the repr should include the args and return code.

IMO it should *not* include the pid, for two reasons:
1. The pid is stale information if the process has finished.
2. Popen nicely abstracts away the pid, so it is normally not as useful a detail.
msg356810 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-11-17 14:09
New changeset 645005e947c13c4a0706310a2a46112bf63cadc0 by Tal Einat (Andrey Doroschenko) in branch 'master':
bpo-38724: Implement subprocess.Popen.__repr__ (GH-17151)
https://github.com/python/cpython/commit/645005e947c13c4a0706310a2a46112bf63cadc0
msg356811 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-11-17 14:09
Thanks for the suggestion Ram, and thanks for PR Andrey!
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82905
2019-11-17 14:09:40taleinatsetstatus: open -> closed
resolution: fixed
messages: + msg356811

stage: patch review -> resolved
2019-11-17 14:09:04taleinatsetmessages: + msg356810
2019-11-14 11:22:38taleinatsetmessages: + msg356598
2019-11-14 10:30:39python-devsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request16660
2019-11-14 05:04:49mdebisetnosy: + mdebi
messages: + msg356576
2019-11-13 22:27:08rhettingersetnosy: + rhettinger
messages: + msg356564
2019-11-13 21:57:18Jason.Killensetmessages: + msg356561
2019-11-13 20:30:37taleinatsetstage: needs patch
2019-11-13 19:48:21taleinatsetkeywords: + easy

messages: + msg356550
2019-11-13 19:35:50Jason.Killensetnosy: + Jason.Killen
2019-11-06 19:46:00ammar2setnosy: + gregory.p.smith
2019-11-06 19:45:07cool-RRsetnosy: + taleinat
2019-11-06 19:44:32cool-RRcreate