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

RuntimeError from ProgressBar

Open
#1,033 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

Managed to get a repro to a short script (Python 3.7.5 on Windows):

import prompt_toolkit as pt
import sys
import time

def main():
    with pt.shortcuts.ProgressBar() as pb:
        for i in pb(range(80)):
            time.sleep(0.01)

if __name__ == '__main__':
    main()

No prompt comes back. When I hit any key, I get:

exception calling callback for <Future at 0x1d41f1833c8 state=finished raised RuntimeError>
Traceback (most recent call last):
  File "c:\utils\anaconda3\envs\cync\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "c:\utils\anaconda3\envs\cync\lib\site-packages\prompt_toolkit\input\win32.py", line 522, in wait
    loop.call_soon_threadsafe(ready)
  File "c:\utils\anaconda3\envs\cync\lib\asyncio\base_events.py", line 728, in call_soon_threadsafe
    self._check_closed()
  File "c:\utils\anaconda3\envs\cync\lib\asyncio\base_events.py", line 475, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\utils\anaconda3\envs\cync\lib\concurrent\futures\_base.py", line 324, in _invoke_callbacks
    callback(self)
  File "c:\utils\anaconda3\envs\cync\lib\asyncio\futures.py", line 362, in _call_set_state
    dest_loop.call_soon_threadsafe(_set_state, destination, source)
  File "c:\utils\anaconda3\envs\cync\lib\asyncio\base_events.py", line 728, in call_soon_threadsafe
    self._check_closed()
  File "c:\utils\anaconda3\envs\cync\lib\asyncio\base_events.py", line 475, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

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 the Windows input implementation at prompt_toolkit/input/win32.py and run the short ProgressBar reproduction on Python 3.7.5 and Windows. Trace the event-loop shutdown and input callback behavior; done means the script returns to the prompt without either RuntimeError shown in the report.

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.