Recent Posts
XML | 10 sec ago
None | 18 sec ago
None | 24 sec ago
Bash | 25 sec ago
JavaScript | 25 sec ago
None | 51 sec ago
XML | 51 sec ago
Bash | 1 min ago
None | 1 min ago
None | 1 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 corey g on the 5th of Feb 2009 09:04:12 PM
Download |
Raw |
Embed |
Report
import threading
import Queue
import time
class ResultWriter(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.q = queue
def run(self):
f = open('foo.txt', 'a')
while True:
try:
item = self.q.get(False)
f.write(item)
f.flush()
except Queue.Empty:
# re-check queue for messages every x sec
time.sleep(.01)
class Foo(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
q = Queue.Queue(0)
t = ResultWriter(q)
t.setDaemon(True)
t.start()
while True:
print 'foo'
q.put('foo')
f = Foo()
f.setDaemon(True)
f.start()
while True:
time.sleep(.1)
Submit a correction or amendment below.
Make A New Post