Recent Posts
None | 7 sec ago
None | 15 sec ago
Per | 1 min ago
None | 1 min ago
None | 1 min ago
T-SQL | 1 min ago
XML | 1 min ago
T-SQL | 1 min ago
None | 1 min ago
Bash | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By Anonymous on the 9th of Feb 2010 11:35:08 PM
Download |
Raw |
Embed |
Report
#!/usr/bin/env python
import threading
import time
called = False
class TwitterUpdater(threading.Thread):
def __init__(self, callback, *args, **kargs):
threading.Thread.__init__(self)
self.callback = callback
self.args = args
self.kargs = kargs
self.stop = False
def run(self):
# This is where we run the main loop
# -- Do the streaming twitter stuff here?
time.sleep(1)
self.callback(*self.args, **self.kargs)
def join(self):
self.stop = True
threading.Thread.join(self)
def my_function(*args, **kargs):
# At the moment we import the global variable 'called', but we could just
# as easily make my_function a class function which stores data there
global called
called = True
if __name__ == "__main__":
try:
# Setup the thread
twitter_updater = TwitterUpdater(my_function)
# Start the thread
twitter_updater.start()
for i in range(10):
time.sleep(0.2)
if called:
print "Called!"
else:
print "Not called yet :("
finally:
# Stop the thread
twitter_updater.join()
Submit a correction or amendment below.
[ previous version ] | [ difference ] | Make A New Post