Commits

Pierre Carbonnelle  committed 85c2b37

fix multi-model initialization bug

  • Participants
  • Parent commits 818d6df

Comments (0)

Files changed (2)

File pyDatalog/Logic.py

 
 import copy
 import threading
-import weakref
 
-try:
-    from . import pyEngine
-except ValueError:
-    import pyEngine
+from . import pyEngine, pyParser
 
 class Logic(object):
     """ 
     tl = threading.local()  # contains the Logic in the current thread
     def __new__(cls, logic=None):
         if isinstance(logic, cls):
+            pyParser.clear()
             Logic.tl.logic = copy.copy(logic) 
             Logic.tl.logic.Subgoals = {}
             Logic.tl.logic.Tasks = None
     
     def __init__(self, logic=None):
         if not (logic) or not (hasattr(self, 'Db')):
+            pyParser.clear()
             pyEngine.clear()  # make sure the singleton has what's needed
             
     def clear(self):

File pyDatalog/examples/threadSafe.py

 @author: pcarbonn
 '''
 
-from pyDatalog import pyDatalog
+from pyDatalog import pyDatalog, Logic
 import random
 import threading
 
 
 def queen(thread_name):
     n = int(random.random() * 8) + 1 # 1 to 8
-    pyDatalog.clear()
+    Logic()
     
     queens(X0)                      <= (X0._in(range(n)))
     queens(X0,X1)                   <= queens(X0)                   & next_queen(X0,X1)