Slide 5
Slide 5 text
4
マルチスレッドについて
class Vehicle(threading.Thread):
def __init__(self, events: Events, location: Location, **kwargs):
super().__init__(**kwargs)
self.done = threading.Event()
...
def run(self):
while not self.done.wait(0):
time.sleep(TIME_STEP)
self._move()
class Timer(threading.Thread):
def __init__(self, events: Events, **kwargs):
super().__init__(**kwargs)
self.done = threading.Event()
...
def run(self):
while not self.done.wait(0):
time.sleep(TIME_STEP)
self.elapsed_time += TIME_STEP
● Timerのスレッド ● Vehicle x nのスレッド
各スレッドが並列動く
(Streamlitではグローバルにキャッシュでスレッドのオブジェクトを保持する必要あり)
@st.cache_resource
def get_root_manager():
return RootManager()