prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.35k stars 716 forks source link

RuntimeError from ProgressBar #1033

Open ivannp opened 4 years ago

ivannp commented 4 years ago

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
jonathanslenders commented 4 years ago

I can reproduce it, although slightly different. In my case, (win10, Python 3.8.1), the progress bar shows and goes until the end, but then it hangs and pressing any key causes this error message.

jonathanslenders commented 4 years ago

Hi @ivannp, can you test whether this PR will fix it? https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1039

XenonR commented 4 years ago

Hello @jonathanslenders, i had the same issue. Your PR #1039 fixes this issue for me. Thanks a lot! (Win10, Py3.7.5)

jonathanslenders commented 4 years ago

Thanks for trying! I'll close this for now. Let me know if there still some issues.

Berserker66 commented 4 years ago

Is this the same problem?

Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Program Files\Python38\lib\site-packages\prompt_toolkit\input\win32.py", line 528, in wait
    loop.call_soon_threadsafe(ready)
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 764, in call_soon_threadsafe
    self._check_closed()
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 508, 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:\Program Files\Python38\lib\concurrent\futures\_base.py", line 328, in _invoke_callbacks
    callback(self)
  File "C:\Program Files\Python38\lib\asyncio\futures.py", line 374, in _call_set_state
    dest_loop.call_soon_threadsafe(_set_state, destination, source)
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 764, in call_soon_threadsafe
    self._check_closed()
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

progressbar and input, both in async tasks,