Created
July 27, 2011 23:41
-
-
Save nfarring/1110611 to your computer and use it in GitHub Desktop.
Python thread example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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