Skip to content
Advertisement

Can not force stop python script using ctrl + C

Normally to force stop python script that are running, we normal just press Ctrl + C (in Interactive console). In this case, it does not stop, when I press Ctrl + C. Here is my code for this situation:

import datetime  
from datetime import timedelta  
x = datetime.datetime.now()
print(x)
i=0
while (datetime.datetime.now()<x + timedelta(seconds=20) ):
    print(i)
    i=i+1

I want it to force it to stop before the 20seconds is reached.


Please help explain why this happened and help find a solution to this.

Advertisement

Answer

It’s just you. It accepted the KeyboardInterrupt for me.

screenshot of KeyboardInterrupt halting execution of program

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement