def __init__(self, num_procs, dirname='file_comm', worker_queue_file='worker_queue', worker_results_prefix='worker_results_'):
    try:
        os.makedirs(dirname)
    except OSError:
        pass
    lock = portalocker.Lock(os.path.join(dirname, 'init'), mode='a+', flags=portalocker.LOCK_EX)
    lock.acquire()
    fh = lock.fh
    fh.seek(0)
    curnum = fh.read()
    if (len(curnum) is 0):
        rank = 0
    else:
        rank = int(curnum)
    if (rank >= num_procs):
        raise ValueError('Number of processes > the number of workers')
    fh.seek(0)
    fh.truncate(0)
    fh.write(str((rank + 1)))
    lock.release()
    super(FileCommunicator, self).__init__((num_procs - 1), rank)
    self.worker_queue_file = os.path.join(dirname, worker_queue_file)
    self.worker_results_prefix = os.path.join(dirname, worker_results_prefix)
    self.done = False
def __init__(self, num_procs, dirname='file_comm', worker_queue_file='worker_queue', worker_results_prefix='worker_results_'):
    try:
        os.makedirs(dirname)
    except OSError:
        pass
    lock = portalocker.Lock(os.path.join(dirname, 'init'), mode='a+', flags=portalocker.LOCK_EX)
    lock.acquire()
    fh = lock.fh
    fh.seek(0)
    curnum = fh.read()
    if (len(curnum) is 0):
        rank = 0
    else:
        rank = int(curnum)
    if (rank >= num_procs):
        raise ValueError('Number of processes > the number of workers')
    fh.seek(0)
    fh.truncate(0)
    fh.write(str((rank + 1)))
    lock.release()
    super(FileCommunicator, self).__init__((num_procs - 1), rank)
    self.worker_queue_file = os.path.join(dirname, worker_queue_file)
    self.worker_results_prefix = os.path.join(dirname, worker_results_prefix)
    self.done = False