After tweaking with this piece of code a few times, I dropped sem.release() in the Server object WITHOUT actually passing the variable sem into it. But it works wonderfully... Can't seem to understand why a error wasn't throw for undeclared variable/reference
import threading,time
class Server(threading.Thread):
def __init__(self, hostname):
super(Server, self).__init__()
self.__hostname = hostname
def run(self):
print self.__hostname+' left'
time.sleep(5)
print self.__hostname+' back'
sem.release()
#init
sem = threading.BoundedSemaphore(2)
for x in xrange(1,8):
sem.acquire()
Server('thread '+str(x)).start()