|
@@ -147,11 +147,7 @@ class Simulator:
|
|
|
self.__realtime_start_time = time.time()
|
|
|
self.__lasttime = 0.0
|
|
|
|
|
|
- # self.__event_thread.start()
|
|
|
- # self.__threading_backend.wait(0, self.__event_thread_loop)
|
|
|
- # self.__event_thread_loop()
|
|
|
- self.__threading_backend_args[0].after(3000, lambda: print("hey"))
|
|
|
- self.__threading_backend.wait(2, lambda: print("ho"))
|
|
|
+ self.__threading_backend.wait(0, self.__event_thread_loop)
|
|
|
self.signal("started")
|
|
|
if self.__realtime:
|
|
|
# Force execute the first iteration now. This way iteration n (n > 0) is
|
|
@@ -175,7 +171,6 @@ class Simulator:
|
|
|
self.__tracer.stopTracers()
|
|
|
self.signal("finished")
|
|
|
self.__finished = True
|
|
|
- # self.__event_thread.join()
|
|
|
|
|
|
def __check(self):
|
|
|
"""
|
|
@@ -407,13 +402,6 @@ class Simulator:
|
|
|
self.__threading_backend_subsystem = subsystem
|
|
|
self.__threading_backend_args = args
|
|
|
|
|
|
- # TODO: allow the user to also do things here?
|
|
|
- # if subsystem == Platform.TKINTER:
|
|
|
- # def cls(s, t):
|
|
|
- # s.__finish()
|
|
|
- # t.destroy()
|
|
|
- # args[0].protocol("WM_DELETE_WINDOW", lambda a=self, b=args[0]: cls(a, b))
|
|
|
-
|
|
|
def setRealTimePlatformThreading(self):
|
|
|
"""
|
|
|
Wrapper around the :func:`setRealTimePlatform` call to automatically
|
|
@@ -487,7 +475,7 @@ class Simulator:
|
|
|
"""
|
|
|
Does a single simulation step.
|
|
|
|
|
|
- Danger:
|
|
|
+ Warning:
|
|
|
Do **not** use this function to forcefully progress the simulation!
|
|
|
All functionalities for validly simulating and executing a system
|
|
|
that are provided through other parts of the interface should be
|
|
@@ -496,7 +484,7 @@ class Simulator:
|
|
|
"""
|
|
|
self.signal("prestep")
|
|
|
curIt = self.__sim_data[2]
|
|
|
- # self.__threading_backend.wait(10, lambda: self.__tracer.traceNewIteration(curIt, self.getTime()))
|
|
|
+ self.__threading_backend.wait(0, lambda: self.__tracer.traceNewIteration(curIt, self.getTime()))
|
|
|
|
|
|
# Efficiency reasons: dep graph only changes at these times
|
|
|
# in the given set of library blocks.
|
|
@@ -580,7 +568,7 @@ class Simulator:
|
|
|
block = component[0] # the strongly connected component has a single element
|
|
|
if curIteration == 0 or self.__scheduler.mustCompute(block, self.getTime()):
|
|
|
block.compute(curIteration)
|
|
|
- # self.__threading_backend.wait(10, lambda: self.__tracer.traceCompute(curIteration, block))
|
|
|
+ self.__threading_backend.wait(0, lambda: self.__tracer.traceCompute(curIteration, block))
|
|
|
else:
|
|
|
# Detected a strongly connected component
|
|
|
self.__solver.checkValidity(self.model.getPath(), component)
|
|
@@ -590,7 +578,7 @@ class Simulator:
|
|
|
if curIteration == 0 or self.__scheduler.mustCompute(block, self.getTime()):
|
|
|
blockIndex = component.index(block)
|
|
|
block.appendToSignal(solutionVector[blockIndex])
|
|
|
- # self.__threading_backend.wait(10, lambda: self.__tracer.traceCompute(curIteration, block))
|
|
|
+ self.__threading_backend.wait(0, lambda: self.__tracer.traceCompute(curIteration, block))
|
|
|
|
|
|
def __hasCycle(self, component, depGraph):
|
|
|
"""
|
|
@@ -632,7 +620,12 @@ class Simulator:
|
|
|
|
|
|
def connect(self, name, function):
|
|
|
"""
|
|
|
- Connect an event with an additional function.
|
|
|
+ Connect an event with an additional, user-defined function. These functions
|
|
|
+ will be executed on a separate thread and polled every 50 milliseconds.
|
|
|
+
|
|
|
+ Warning:
|
|
|
+ It is expected that the passed function terminates at a certain point
|
|
|
+ in time, to prevent an infinitely running process.
|
|
|
|
|
|
The functions will be called in the order they were connected to the
|
|
|
events, with the associated arguments. The accepted signals are:
|
|
@@ -650,10 +643,6 @@ class Simulator:
|
|
|
name (str): The name of the signal to raise.
|
|
|
function: A function that will be called with the optional arguments
|
|
|
whenever the event is raised.
|
|
|
-
|
|
|
- Warning:
|
|
|
- While these functions will be handled on a different thread, it heavy
|
|
|
- computations will eventually result in a delay of all events.
|
|
|
"""
|
|
|
if name not in self.__events:
|
|
|
raise ValueError("Invalid signal '%s' in Simulator." % name)
|
|
@@ -689,14 +678,11 @@ class Simulator:
|
|
|
self.__event_bus.append((name, args))
|
|
|
|
|
|
def __event_thread_loop(self):
|
|
|
- print("looping")
|
|
|
if not self.__finished:
|
|
|
while len(self.__event_bus) > 0:
|
|
|
name, args = self.__event_bus.pop()
|
|
|
for evt in self.__events[name]:
|
|
|
- evt(*args)
|
|
|
- # time.sleep(0.05)
|
|
|
- print("hello there")
|
|
|
+ self.__threading_backend.wait(0, evt(*args))
|
|
|
self.__threading_backend.wait(0.05, self.__event_thread_loop)
|
|
|
|
|
|
def setCustomTracer(self, *tracer):
|
|
@@ -736,7 +722,7 @@ class Simulator:
|
|
|
to multiple files is possible, though more inefficient than simply (manually) copying
|
|
|
the file at the end.
|
|
|
|
|
|
- Danger:
|
|
|
+ Warning:
|
|
|
Using multiple verbose tracers with the same filename will yield errors and undefined
|
|
|
behaviour.
|
|
|
"""
|