Skip to content

Instantly share code, notes, and snippets.

@teshanshanuka
Created July 1, 2018 08:03
Show Gist options
  • Save teshanshanuka/bb741ca3232881739f6739cf865a77ff to your computer and use it in GitHub Desktop.
Save teshanshanuka/bb741ca3232881739f6739cf865a77ff to your computer and use it in GitHub Desktop.
import time, signal
def exit_gracefully(signum, frame):
global exit_now
exit_now = True
signal.signal(signal.SIGTERM, exit_gracefully)
filename = "/home/<username>/myprogram/logs/myservice.log"
exit_now = False
with open(filename, "w") as fl:
while not exit_now:
fl.write(time.ctime() + '\n')
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment