prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Application.run_async leaking memory

Open
#1,057 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

Upon running the example code in examples\prompts\asyncio-prompt.py, I noticed the memory usage climbed rapidly and consistently on my machine -- simply leaving the application sit without doing anything with it would have python.exe using a gigabyte or more of RAM in a few minutes. This was run on a Windows 10 machine running Python 3.8.1.

A bit of investigation later, it appears that the issue may be the underlying app.run_async call is adding thousands of tasks to event loop during its execution. Modifying line 30 of the asyncio-prompt.py example file from its current print statement to print(f'Tasks: {len(asyncio.all_tasks())}') shows that the number of active tasks in the event loop grows very quickly during execution:
image

This is only an issue with the current master branch version -- it does not occur in prompt-toolkit 3.0.2 from pip, but I figured the issue might still be of use to report.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with examples/prompts/asyncio-prompt.py, especially line 30 and the app.run_async call. Reproduce the report with asyncio.all_tasks() while comparing the current master behavior with prompt-toolkit 3.0.2 from pip. Done means the example no longer accumulates tasks or rapidly increases memory while remaining usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.