Pierre Carbonnelle avatar Pierre Carbonnelle committed d1462de

Logic(True) now returns the logic in the current thread. Logic() reinitializes it.

Comments (0)

Files changed (2)

pyDatalog/Logic.py

 class Logic(object):
     """ 
     per-thread singleton class containing the pyEngine Logic in the current thread.
-    Logic() returns the pyEngine logic in the current thread, so that it can be passed to another thread.
+    Logic() resets the logic in the current thread and returns it
+    Logic(True) returns the pyEngine logic in the current thread, so that it can be passed to another thread.
     Logic(logic) initializes the logic in the current thread with logic, and returns it.
     """
-    tl = threading.local() # contains the Logic in the current thread
+    tl = threading.local()  # contains the Logic in the current thread
     def __new__(cls, logic=None):
         if isinstance(logic, cls):
             Logic.tl.logic = copy.copy(logic) 
         return Logic.tl.logic
     
     def __init__(self, logic=None):
-        if not (logic) and not (hasattr(self, 'Db')):
-            pyEngine.clear() # make sure the singleton has what's needed
+        if not (logic) or not (hasattr(self, 'Db')):
+            pyEngine.clear()  # make sure the singleton has what's needed
             
     def clear(self):
         """ move the logic to the current thread and clears it """
-        Logic(self) # just to be sure
+        Logic(self)  # just to be sure
         pyEngine.clear()
                 
-pyEngine.Logic = Logic # share Logic with pyEngine
+pyEngine.Logic = Logic  # share Logic with pyEngine

pyDatalog/pyDatalog.py

 
 try:
     from . import version
+    from . import Logic
     from . import pyEngine
     from . import pyParser
     from . import util
 except ValueError:
     import version
+    import Logic
     import pyEngine
     import pyParser
     import util
 def clear():
     """ resets the default datalog database """
     pyParser.clear()
-    pyEngine.clear()
+    Logic()
 
 def create_atoms(*args):
     """ create atoms for in-line queries """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.