KeyboardInterrupt wird nicht abgefangen, wenn die Blockierungsarbeit erledigt istPython

Python-Programme
Anonymous
 KeyboardInterrupt wird nicht abgefangen, wenn die Blockierungsarbeit erledigt ist

Post by Anonymous »

Um den folgenden Code zu stoppen, müssen Sie zweimal Strg-C drücken. Die zweite ausgelöste KeyboardInterrupt-Ausnahme wird jedoch nicht vom inneren Try-Catch innerhalb der start_sumption-Methode abgefangen.

Code: Select all

import asyncio

async def start_consuming():
try:
await asyncio.Future()
except:
try:
await asyncio.Future()
except:
pass

async def main():
await asyncio.gather(start_consuming())

if __name__ == '__main__':
asyncio.run(main())
Warum?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post