I have a script where I want to put function, maybe time()
to print for example "One hour of running" after some elapsed time while code is running.
For example
I start the script, after 1 hour maybe to print "Hour since running!" and after, every hour to display that. Is that even possible?
Thank you!
Asked
Active
Viewed 94 times
1

Uvu
- 77
- 1
- 1
- 8
1 Answers
0
You can do it with signal
:
import signal
# Setup a signal handler
signal.signal(signal.SIGALRM,
lambda x,y: # You can put any function here
print("One hour since running!"))
# Request a signal 3600 secs later
signal.alarm(3600)
# Now, do your stuff
# 1 hr later:
# One hour since running!

DYZ
- 55,249
- 10
- 64
- 93
-
It would be the great solution, but signal and alarm are not working on windows OS... :( – Uvu Dec 02 '16 at 23:56
-
You didn't say you use Windows. Try this, then: http://stackoverflow.com/questions/644073/signal-alarm-replacement-in-windows-python – DYZ Dec 03 '16 at 00:03
-
Helped a lot, thank you – Uvu Dec 03 '16 at 00:08