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...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 9th of Feb 2010 11:35:08 PM Download | Raw | Embed | Report
  1. #!/usr/bin/env python
  2.  
  3. import threading
  4. import time
  5.  
  6. called = False
  7.  
  8. class TwitterUpdater(threading.Thread):
  9.     def __init__(self, callback, *args, **kargs):
  10.         threading.Thread.__init__(self)
  11.         self.callback = callback
  12.         self.args = args
  13.         self.kargs = kargs
  14.         self.stop = False
  15.    
  16.     def run(self):
  17.         # This is where we run the main loop
  18.         # -- Do the streaming twitter stuff here?
  19.         time.sleep(1)
  20.         self.callback(*self.args, **self.kargs)
  21.            
  22.     def join(self):
  23.         self.stop = True
  24.         threading.Thread.join(self)
  25.  
  26. def my_function(*args, **kargs):
  27.     # At the moment we import the global variable 'called', but we could just
  28.     # as easily make my_function a class function which stores data there
  29.     global called
  30.     called = True
  31.    
  32. if __name__ == "__main__":
  33.     try:
  34.         # Setup the thread
  35.         twitter_updater = TwitterUpdater(my_function)
  36.         # Start the thread
  37.         twitter_updater.start()
  38.         for i in range(10):
  39.             time.sleep(0.2)
  40.             if called:
  41.                 print "Called!"
  42.             else:
  43.                 print "Not called yet :("
  44.        
  45.     finally:
  46.         # Stop the thread
  47.         twitter_updater.join()
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: