Blocking until condition is met I have a class called _NodeProcess. It consists of a mainloop (main function) which is run in a separate process and methods (start and stop) that control the mainloop. Here's the code: 

class _NodeProcess:
    def __init__(self, master):
        self.master = master
        self.process = multiprocessing.Process(target=self.main)
        self.is_alive = True
        self.is_dead = False

    def start(self):
        self.process.start()

    def stop(self):
        self.is_alive = False
        while not self.is_dead:
            pass

    def main(self):
        while self.is_alive:
            task = self.master.give_task()
            self.master.grab_result({'header': 'result', 'result': self.master.function(task), 'task': task})
        self.is_dead = True


The part that worries me is the stop function. On each mainloop iteration, I check whether I should continue (self.is_alive == True), and if I shouldn't, I stop and do self.is_dead = True to confirm that i had quit the loop. Meanwile, in the stop function, after setiing self.is_alive to False, and block until self.is_dead == True.

My concern is the way in which I block:

while not self.is_dead:
    pass


I'm afraid it may eat to much resources just iterating over that loop at a very high speed. So, I considered another option, using time.sleep:

import time

while not self.is_dead:
    time.sleep(1)


But it doesn't seem like a best way to block until some condition is met (I need an extra library; I lose 0.5 seconds on average when I call the stop method, if I make the period less, I spend more resources, so it's some kind of a compromise, which has to be made each time I write code like that). Is there a better solution for this particular problem, or maybe it's better to redesign the class in some way that would allow not facing this problem at all?
You don't need a self.is_dead. You simply need to block until the thread is complete. For that, we have join():

def stop(self):
    self.is_alive = False
    self.process.join()