prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Ctrl-C and Ctrl-D cause ResourceWarning to disappear on Python 3.9
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
We noticed a strange behavior in our pywbemtools project and I was wondering whether you had any explanation for this. Note, this is just a question and it may not be an issue in prompt-toolkit.
The pywbemtools project has a pywbemcli command line tool that uses click with click-repl for its interactive mode. When stdin.isatty() (i.e. stdin not redirected), click-repl uses prompt-toolkit for the interactive repl loop.
We currently get a ResourceWarning on Python 3 due to an unclosed socket. We will fix that by closing it, but that is not the point of my question.
What we see is that when the interactive session is terminated with Ctrl-D or when there is a Ctrl-C (which is ignored by click-repl), then we do not see the ResourceWarning on Python 3.9. If this is done on Python 3.7 or 3.8, the ResourceWarning does show up as it should. Also, when the interactive session is terminated via a click-repl internal command (it supports :q for that purpose), the ResourceWarning does show up on all Python versions as it should. It is only the combination of using Ctrl-C/D on only Python 3.9 that makes it disappear.
The click-repl version (0.1.6) and prompt-toolkit version (3.0.16) are the same on all these Python versions.
In the cases where the ResourceWarning does not show up, prompt-toolkit handles the Ctrl-C/D by calling self.app.exit(); whether this call is made correlates to 100% with the ResourceWarning not showing up. But just on Python 3.9.
More details are documented here: https://github.com/pywbem/pywbemtools/issues/883#issuecomment-784771188
My question is: Do you have an explanation on why the ResourceWarning does not show up in these cases?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Ctrl-C, Ctrl-D, and :q cases in the prompt-toolkit interactive loop described in the issue, comparing Python 3.7, 3.8, and 3.9. Trace the path where self.app.exit() is called and compare it with normal command termination. Done means explaining why the ResourceWarning disappears only in the Python 3.9 cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100