Mar-06-2020, 07:17 AM
I am very new to python. I have a little program and I want it run in the following order :
- First I set a method
- I run my test file by command prompt.
- While the program is performing a suspension of 10 seconds, suddenly I click the X close button in the top-right corner of the window, the program will not immediately shut down but it will run command
I wrote the code below but I'm still stuck. Would someone please tell me how to do it? Thank you.
- First I set a method
time.sleep(10)within code to suspends execution for the 10 seconds in my test file.
- I run my test file by command prompt.
- While the program is performing a suspension of 10 seconds, suddenly I click the X close button in the top-right corner of the window, the program will not immediately shut down but it will run command
print('Close terminal event detected.')and delay about 1 second by
time.sleep(1)before it shuts off.
I wrote the code below but I'm still stuck. Would someone please tell me how to do it? Thank you.
import time import os time.sleep(10) # If the terminal is closed while time.sleep(10) is running, the program will print the following line and run time.sleep(1) before exiting print('Close terminal event detected.') time.sleep(1)