break/interrupt a time.sleep() in python

后端 未结 6 1482
猫巷女王i
猫巷女王i 2020-12-01 03:30

I need to break from time.sleep() using ctrl c.

While 1:
    time.sleep(60)

In the above code when the control enters time.sleep function a

6条回答
  •  余生分开走
    2020-12-01 03:45

    Not sure what the sense of this code is - but if necessary use a shorter sleep() interval and put a for loop around it:

    for i in range(60):
       sleep(1)
    

    Catching the KeyboardInterrupt exception using try..except is straight-forward

提交回复
热议问题