'When parallel processing, don\'t want each worker to generate its own terrain. This method ensures that
one worker generates the terrain, which is then used by other workers.
It\'s still possible to have each worker use their own terrain by passing each worker a different hfield and
texture dir.'

def _iam_terrain_generator(self, regen):

    if (not os.path.exists(self.hfield_dir)):
        os.makedirs(self.hfield_dir)
    terrain_path = os.path.join(self.hfield_dir, self.HFIELD_FNAME)
    lock_path = self._get_lock_path()
    if (regen or ((not regen) and (not os.path.exists(terrain_path)))):
        if (not os.path.exists(lock_path)):
            with open(lock_path, 'w') as f:
                f.write(str(os.getpid()))
            return True
        else:
            total = 0
            logger.log('Process    {0}    waiting    for    terrain    generation...'.format(os.getpid()))
            while (os.path.exists(lock_path) and (total < 120)):
                time.sleep(5)
                total += 5
            if os.path.exists(lock_path):
                raise 'Process    {0}    timed    out    waiting    for    terrain    generation,    or    stale    lock    file'.format(os.getpid())
            logger.log('Done.')
            return False
