from six import next
-from nepi.util import guid
from nepi.util.parallel import ParallelRun
from nepi.util.timefuncs import tnow, tdiffsec, stabsformat, tsformat
from nepi.execution.resource import ResourceFactory, ResourceAction, \
RELEASED = 3
TERMINATED = 4
+# historical note: this class used to be in util/guid.py but is used only here
+# FIXME: This class is not thread-safe. Should it be made thread-safe?
+class GuidGenerator(object):
+ def __init__(self):
+ self._last_guid = 0
+
+ # historical note: this used to be called `next`
+ # which confused 2to3 - and me - while it has
+ # nothing to do at all with the iteration protocol
+ def generate(self, guid = None):
+ if guid == None:
+ guid = self._last_guid + 1
+
+ self._last_guid = self._last_guid if guid <= self._last_guid else guid
+
+ return guid
+
class ExperimentController(object):
"""
.. note::
self._persist = persist
# generator of globally unique ids
- self._guid_generator = guid.GuidGenerator()
+ self._guid_generator = GuidGenerator()
# Resource managers
self._resources = dict()
self._groups = dict()
# generator of globally unique id for groups
- self._group_id_generator = guid.GuidGenerator()
+ self._group_id_generator = GuidGenerator()
# Flag to stop processing thread
self._stop = False
"""
# Get next available guid
# xxx_next_hiccup
- guid = self._guid_generator.next(guid)
+ guid = self._guid_generator.generate(guid)
# Instantiate RM
rm = ResourceFactory.create(rtype, self, guid)
if not group:
new_group = True
# xxx_next_hiccup
- group = self._group_id_generator.next()
+ group = self._group_id_generator.generate()
if group not in self._groups:
self._groups[group] = []