Skip to content

Instantly share code, notes, and snippets.

@mccricardo
Created October 22, 2013 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mccricardo/7107649 to your computer and use it in GitHub Desktop.
Save mccricardo/7107649 to your computer and use it in GitHub Desktop.
from threading import Thread
from Queue import Queue
class Adding:
def __init__(self):
self.added = False
self.value = 0
def has_added(self):
return self.added
def add(self):
print "Adding...\n"
self.value +=1
self.added = True
def get_value(self):
return self.value
def do_add():
adding = q.get()
adding.add()
q.task_done()
q = Queue()
adding = Adding()
q.put(adding)
for i in xrange(5):
t = Thread(target=do_add)
t.daemon = True
t.start()
print "Value: %s" % adding.get_value()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment