'Test that we handle thread creation problems ok.'

def testFailToCreateThread(self):

    self.assertEqual(len(self.test_pool), self.NUMBER_OF_THREADS)
    done_event = threading.Event()
    def Block(done):
        done.wait()
    def RaisingStart(_):
        raise threading.ThreadError()
    with utils.Stubber(threadpool._WorkerThread, 'start', RaisingStart):
        self.test_pool.AddTask(Block, (done_event,))
        self.WaitUntil((lambda : (self.test_pool.busy_threads == self.NUMBER_OF_THREADS)))
        for _ in range(self.MAXIMUM_THREADS):
            self.test_pool.AddTask(Block, (done_event,))
        self.assertRaises(threadpool.Full, self.test_pool.AddTask, Block, (done_event,), blocking=False, inline=False)
        done_event.set()
        self.test_pool.Join()
