Przeglądaj źródła

Python3 Updates

rparedis 3 lat temu
rodzic
commit
50164a92c6

+ 1 - 0
.gitignore

@@ -9,3 +9,4 @@
 *.pyc
 *build*
 test/output/*
+/.idea/*

+ 4 - 1
doc/experiment_tk.py

@@ -15,7 +15,10 @@
 
 from pypdevs.simulator import Simulator
 
-from Tkinter import *
+try:
+    from Tkinter import *
+except ImportError:
+    from tkinter import *
 from trafficLightModel import *
 
 isBlinking = None

+ 4 - 1
examples/trafficlight_realtime/experiment_tk.py

@@ -15,7 +15,10 @@
 
 from pypdevs.simulator import Simulator
 
-from Tkinter import *
+try:
+    from Tkinter import *
+except ImportError:
+    from tkinter import *
 from trafficLightModel import *
 
 isBlinking = None

+ 7 - 3
src/pypdevs/realtime/threadingGameLoop.py

@@ -16,6 +16,9 @@
 import pypdevs.accurate_time as time
 from threading import Lock
 
+_GLLOCK = Lock()
+
+
 class ThreadingGameLoop(object):
     """
     Game loop subsystem for realtime simulation. Time will only progress when a *step* call is made.
@@ -30,9 +33,10 @@ class ThreadingGameLoop(object):
         """
         Perform a step in the simulation. Actual processing is done in a seperate thread.
         """
-        if time.time() >= self.next_event:
-            self.next_event = float('inf')
-            getattr(self, "func")()
+        with _GLLOCK:  # Thread-safety
+            if time.time() >= self.next_event:
+                self.next_event = float('inf')
+                getattr(self, "func")()
         
     def wait(self, delay, func):
         """

+ 3 - 1
src/pypdevs/util.py

@@ -144,7 +144,9 @@ class DEVSException(Exception):
         """
         String representation of the exception
         """
-        return "DEVS Exception: " + str(self.message)
+        if hasattr(self, "message"):
+            return "DEVS Exception: " + str(self.message)
+        return "DEVS Exception: " + str(self.args[0])
 
 class QuickStopException(Exception):
     """

+ 4 - 1
test/testmodels/experiment.py

@@ -185,7 +185,10 @@ elif mn.startswith("realtime"):
     elif mn.startswith("realtime_loop"):
         args["setRealTimePlatformGameLoop"] = []
     elif mn.startswith("realtime_tk"):
-        from Tkinter import *
+        try:
+            from Tkinter import *
+        except ImportError:
+            from tkinter import *
         myTk = Tk()
         args["setRealTimePlatformTk"] = [myTk]
     else:

+ 3 - 3
test/testmodels/stacktracer.py

@@ -73,7 +73,7 @@ class TraceDumper(threading.Thread):
             pass
     
     def stacktraces(self):
-        fout = file(self.fpath,"wb+")
+        fout = open(self.fpath,"wb+")
         try:
             fout.write(stacktraces())
         finally:
@@ -97,5 +97,5 @@ def trace_stop():
     if _tracer is None:
         raise Exception("Not tracing, cannot stop.")
     else:
-        _trace.stop()
-        _trace = None
+        _tracer.stop()
+        _tracer = None