Python3 Updates
This commit is contained in:
parent
190a70532a
commit
50164a92c6
7 changed files with 26 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -9,3 +9,4 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
*build*
|
*build*
|
||||||
test/output/*
|
test/output/*
|
||||||
|
/.idea/*
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,10 @@
|
||||||
|
|
||||||
from pypdevs.simulator import Simulator
|
from pypdevs.simulator import Simulator
|
||||||
|
|
||||||
|
try:
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
|
except ImportError:
|
||||||
|
from tkinter import *
|
||||||
from trafficLightModel import *
|
from trafficLightModel import *
|
||||||
|
|
||||||
isBlinking = None
|
isBlinking = None
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,10 @@
|
||||||
|
|
||||||
from pypdevs.simulator import Simulator
|
from pypdevs.simulator import Simulator
|
||||||
|
|
||||||
|
try:
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
|
except ImportError:
|
||||||
|
from tkinter import *
|
||||||
from trafficLightModel import *
|
from trafficLightModel import *
|
||||||
|
|
||||||
isBlinking = None
|
isBlinking = None
|
||||||
|
|
|
||||||
|
|
@ -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,6 +33,7 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
with _GLLOCK: # Thread-safety
|
||||||
if time.time() >= self.next_event:
|
if time.time() >= self.next_event:
|
||||||
self.next_event = float('inf')
|
self.next_event = float('inf')
|
||||||
getattr(self, "func")()
|
getattr(self, "func")()
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,9 @@ class DEVSException(Exception):
|
||||||
"""
|
"""
|
||||||
String representation of the exception
|
String representation of the exception
|
||||||
"""
|
"""
|
||||||
|
if hasattr(self, "message"):
|
||||||
return "DEVS Exception: " + str(self.message)
|
return "DEVS Exception: " + str(self.message)
|
||||||
|
return "DEVS Exception: " + str(self.args[0])
|
||||||
|
|
||||||
class QuickStopException(Exception):
|
class QuickStopException(Exception):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -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"):
|
||||||
|
try:
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
|
except ImportError:
|
||||||
|
from tkinter import *
|
||||||
myTk = Tk()
|
myTk = Tk()
|
||||||
args["setRealTimePlatformTk"] = [myTk]
|
args["setRealTimePlatformTk"] = [myTk]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue