Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with asyncio still print still after ctrl-c in ipython #205

Closed
NewUserHa opened this issue Dec 2, 2022 · 3 comments
Closed

with asyncio still print still after ctrl-c in ipython #205

NewUserHa opened this issue Dec 2, 2022 · 3 comments

Comments

@NewUserHa
Copy link

NewUserHa commented Dec 2, 2022

import asyncio
from alive_progress import alive_bar

letters = [chr(ord('A') + x) for x in range(26)]
with alive_bar(26, dual_line=True, title='Alphabet') as bar:
    for c in letters:
        bar.text = f'-> Teaching the letter: {c}, please wait...'
        if c in 'HKWZ':
            print(f'fail "{c}", retry later')
        await asyncio.sleep(0.3)
        bar()
@NewUserHa
Copy link
Author

may relate to ipython/ipython#13850

@rsalmei
Copy link
Owner

rsalmei commented Jan 1, 2023

Interesting... I can reproduce it, but I'm not sure why this happens.
I know internally I start a thread for the rendering work, but I've included a try/finally that stops it!!!
It does seem related to ipython, because as far as I know, an async code must be run inside an async loop, and since this code doesn't start one, ipython must be doing it.
Actually, the CTRL+C stack trace does show a run_until_complete call:

on 5: ---------------------------------------------------------------------------
      KeyboardInterrupt                         Traceback (most recent call last)
      ~/.pyenv/versions/3.7.12/envs/alive37/lib/python3.7/site-packages/IPython/core/async_helpers.py in __call__(self, coro)
           36         Handler for asyncio autoawait
           37         """
      ---> 38         return self.loop.run_until_complete(coro)
           39
           40     def __str__(self):

      ~/.pyenv/versions/3.7.12/lib/python3.7/asyncio/base_events.py in run_until_complete(self, future)
          572         future.add_done_callback(_run_until_complete_cb)
          573         try:
      --> 574             self.run_forever()
          575         except:
          576             if new_task and future.done() and not future.cancelled():

      ~/.pyenv/versions/3.7.12/lib/python3.7/asyncio/base_events.py in run_forever(self)
          539             events._set_running_loop(self)
          540             while True:
      --> 541                 self._run_once()
          542                 if self._stopping:
          543                     break

      ~/.pyenv/versions/3.7.12/lib/python3.7/asyncio/base_events.py in _run_once(self)
         1748                            timeout * 1e3, dt * 1e3)
         1749         else:
      -> 1750             event_list = self._selector.select(timeout)
         1751         self._process_events(event_list)
         1752

      ~/.pyenv/versions/3.7.12/lib/python3.7/selectors.py in select(self, timeout)
          556             ready = []
          557             try:
      --> 558                 kev_list = self._selector.control(None, max_ev, timeout)
          559             except InterruptedError:
          560                 return ready

      KeyboardInterrupt:

@rsalmei
Copy link
Owner

rsalmei commented May 26, 2023

I'm closing this one because unfortunately, I can't do anything about it.

@rsalmei rsalmei closed this as completed May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants