Python3 Updates

This commit is contained in:
rparedis 2022-03-02 15:21:39 +01:00
parent 190a70532a
commit 50164a92c6
7 changed files with 26 additions and 10 deletions

1
.gitignore vendored
View file

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

View file

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

View file

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

View file

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

View file

@ -144,7 +144,9 @@ class DEVSException(Exception):
""" """
String representation of the 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): class QuickStopException(Exception):
""" """

View file

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

View file

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