[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2022-03-30 Thread Andrew Svetlov
Andrew Svetlov added the comment: New changeset f08a191882f75bb79d42a49039892105b2212fb9 by Andrew Svetlov in branch 'main': bpo-39622: Interrupt the main asyncio task on Ctrl+C (GH-32105) https://github.com/python/cpython/commit/f08a191882f75bb79d42a49039892105b2212fb9 --

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2022-03-24 Thread Andrew Svetlov
Change by Andrew Svetlov : -- pull_requests: +30184 pull_request: https://github.com/python/cpython/pull/32105 ___ Python tracker ___

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2022-03-17 Thread Andrew Svetlov
Change by Andrew Svetlov : -- assignee: -> asvetlov ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-03-08 Thread Maor Kleinberger
Maor Kleinberger added the comment: Hey there, it's been more than a week since I pushed the last changes, can anyone review them? -- ___ Python tracker ___

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-28 Thread Maor Kleinberger
Change by Maor Kleinberger : -- versions: +Python 3.8, Python 3.9 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-26 Thread Maor Kleinberger
Maor Kleinberger added the comment: I have pushed an update to my PR. While implementing the new solution I made the following list: Examples for code segments where KeyboardInterrupt must not be raised: - Between popping and running a handle from the ready queue (a handle is lost) - After

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-25 Thread Maor Kleinberger
Maor Kleinberger added the comment: While looking into this proposal, I realized that this will not wake up the loop from the select call. I think the safest solution would be to use the wakeup fd mechanism. An additional easy, but less secure solution would be to define an internal

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-25 Thread Maor Kleinberger
Maor Kleinberger added the comment: Damn, good catch. How about the following idea - register a normal signal handler (using signal.signal) that does something like: def sigint_handler(): get_running_loop().interrupt() # in class BaseEventLoop def interrupt(self): # Might be a

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-24 Thread Zhibin Dong
Zhibin Dong added the comment: Yes, I think you are right. In the second solution, the callback of SIGINT will be append to the end of one task loop. If that code is defined in a task by some user, KeyboardInterrupt will not be raised. -- ___

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-24 Thread Andrew Svetlov
Andrew Svetlov added the comment: The second solution doesn't help with breaking infinite loops like while True: pass We need a more robust idea. -- ___ Python tracker

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-23 Thread Maor Kleinberger
Maor Kleinberger added the comment: After opening the PR, I see that add_signal_handler is not supported on non-unix event loop. After looking at the code, it seems there is no problem to implement it for other platforms, as it relies on signal.set_wakeup_fd() which seems to support all

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-23 Thread Maor Kleinberger
Maor Kleinberger added the comment: After digging into asyncio, I stumbled upon this particularly suspicious block in BaseEventLoop._run_once: https://github.com/python/cpython/blob/v3.9.0a3/Lib/asyncio/base_events.py#L1873 handle = self._ready.popleft() if handle._cancelled: continue

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-23 Thread Maor Kleinberger
Change by Maor Kleinberger : -- keywords: +patch pull_requests: +17992 stage: -> patch review pull_request: https://github.com/python/cpython/pull/18628 ___ Python tracker

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-20 Thread Zhibin Dong
Zhibin Dong added the comment: Thank you for your investigation, I will also try to see what went wrong. -- ___ Python tracker ___

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-20 Thread Maor Kleinberger
Maor Kleinberger added the comment: I wrote a small script that checks the behavior of asyncio.sleep when called with small amounts of time (starting from 0). For each amount I checked 500 times whether SleepTest has stopped when interrupted with SIGINT. Below are the results: SLEEP TIME

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-20 Thread Maor Kleinberger
Maor Kleinberger added the comment: This behaved similarly on my machine, also ubuntu. But it also happened (less often) with small numbers, like sleep(0.01). Also, I tried it on my windows 10 and experienced another unexpected behavior - only when using sleep(0), Ctrl-C

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-19 Thread Zhibin Dong
Zhibin Dong added the comment: Ubuntu 18.04.4 with kernel 5.3.0-28-generic. Additionally Python version is 3.7.3. -- ___ Python tracker ___

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-19 Thread Maor Kleinberger
Maor Kleinberger added the comment: On which OS did that happen? -- nosy: +kmaork ___ Python tracker ___ ___ Python-bugs-list

[issue39622] KeyboardInterrupt is ignored when await asyncio.sleep(0)

2020-02-12 Thread Zhibin Dong
New submission from Zhibin Dong : As shown in the code, when 0 is passed to asyncio.sleep function, sometimes the program does not exit when I press . I must press again to close the program. However, when a number, such as 0.01, which is bigger than 0, is passed to the sleep function, the