class Pipe: def __init__(self): self.data=[] # the pipe is true if there are data in it def __nonzero__(self): return bool(self.data) def read(self): return self.data.pop() def write(self,item): self.data.append(item) def feeder(pipe): while True: if not pipe: pipe.write(1) thePipe=Pipe() import thread thread.start_new_thread(feeder,(thePipe,)) while True: if thePipe and thePipe.read()==2: # should be false! print "How can this happen?"