Untitled
By: a guest | Feb 9th, 2010 | Syntax:
Python | Size: 1.01 KB | Hits: 27 | Expires: Never
#!/usr/bin/env python
import threading
import time
class TwitterUpdater(threading.Thread):
def __init__(self, shared_data, *args, **kargs):
threading.Thread.__init__(self)
self.shared_data = shared_data
self.stop = False
def run(self):
# This is where we run the main loop
# -- Do the streaming twitter stuff here?
i = 1
while not self.stop:
time.sleep(1)
self.shared_data['something'] = i
i += 1
def join(self):
self.stop = True
threading.Thread.join(self)
if __name__ == "__main__":
try:
# Create our shared data
d = {'something': 0}
# Setup the thread
twitter_updater = TwitterUpdater(d)
# Start the thread
twitter_updater.start()
for i in range(100):
print d['something']
time.sleep(0.2)
finally:
# Stop the thread
twitter_updater.join()