Commit c2b88ecb authored by Jerome Mariette's avatar Jerome Mariette
Browse files

No commit message

No commit message
parent f93ed3f7
......@@ -23,6 +23,7 @@ import sys
import imp
import os
import pickle
import threading
import jflow.utils as utils
from jflow.config_reader import JFlowConfigReader
......@@ -34,6 +35,8 @@ class WorkflowsManager(object):
IDS_FILE_NAME = "jflowIDs.txt"
WF_DIRECTORY_PREFIX = "wf"
lock_ids_file = threading.Lock()
def __init__(self):
"""
"""
......@@ -126,16 +129,22 @@ class WorkflowsManager(object):
self.WF_DIRECTORY_PREFIX + utils.get_nb_string(wid))
def get_next_id(self):
if os.path.isfile(self.ids_file):
ifh = open(self.ids_file)
cid = int(ifh.readline().strip())
ifh.close()
ifh = open(self.ids_file, "w")
ifh.write(str(cid+1))
ifh.close()
return cid+1
else:
ifh = open(self.ids_file, "w")
ifh.write("1")
ifh.close()
return 1
WorkflowsManager.lock_ids_file.acquire()
cid = 1
try:
if os.path.isfile(self.ids_file):
ifh = open(self.ids_file)
cid = int(ifh.readline().strip())
ifh.close()
ifh = open(self.ids_file, "w")
ifh.write(str(cid+1))
ifh.close()
return cid+1
else:
ifh = open(self.ids_file, "w")
ifh.write("1")
ifh.close()
finally:
WorkflowsManager.lock_ids_file.release()
return cid
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment