Skip to content

Instantly share code, notes, and snippets.

@nfarring
Created July 27, 2011 23:41
Show Gist options
  • Save nfarring/1110611 to your computer and use it in GitHub Desktop.
Save nfarring/1110611 to your computer and use it in GitHub Desktop.
Python thread example
#!/usr/bin/env python
# This script creates a daemon thread named 'watchdog_timer' that runs the watchdog_timer() function.
# The main thread sleeps in an infinite loop until you press control-C.
# Since the watchdog_timer thread is a daemon, exiting the main thread will exit the entire process.
import threading
import time
def watchdog_timer():
while True:
print('online')
time.sleep(5)
if __name__=='__main__':
t1 = threading.Thread(target=watchdog_timer,name='watchdog_timer')
t1.daemon = True
t1.start()
while True:
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment