summaryrefslogtreecommitdiff
path: root/factory/declarations.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-05-11 16:19:20 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-05-11 16:19:20 +0200
commit6df2ca02df8b07650b708491db8001c07cb72061 (patch)
tree58b3ebf347344e873d92703d3fcb2b417274d7e3 /factory/declarations.py
parent918daab6bbaf205f12927671f902a56eca46a3ec (diff)
downloadfactory-boy-6df2ca02df8b07650b708491db8001c07cb72061.tar
factory-boy-6df2ca02df8b07650b708491db8001c07cb72061.tar.gz
Fix concurrency between declarations for LazyAttributes and Sequence.
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'factory/declarations.py')
-rw-r--r--factory/declarations.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/factory/declarations.py b/factory/declarations.py
index cf54f07..4c44e0c 100644
--- a/factory/declarations.py
+++ b/factory/declarations.py
@@ -18,6 +18,23 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
+import threading
+
+global_counter_lock = threading.Lock()
+
+class GlobalCounter(object):
+ """A simple global counter."""
+
+ _value = 0
+
+ @classmethod
+ def step(cls):
+ with global_counter_lock:
+ current = cls._value
+ cls._value += 1
+ return current
+
+
class OrderedDeclaration(object):
'''A factory declaration.
@@ -26,13 +43,7 @@ class OrderedDeclaration(object):
_next_order = 0
def __init__(self):
- self.order = self.next_order()
-
- @classmethod
- def next_order(cls):
- next_order = cls._next_order
- cls._next_order += 1
- return next_order
+ self.order = GlobalCounter.step()
def evaluate(self, factory, attributes):
'''Evaluate this declaration.