diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index 535514e521..2d11ab649d 100644 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -36,11 +36,16 @@ class UnknownKeyName(Exception): cdef class Params: cdef c_Params* p + cdef str d def __cinit__(self, d=""): cdef string path = d.encode() with nogil: self.p = new c_Params(path) + self.d = d + + def __reduce__(self): + return (type(self), (self.d,)) def __dealloc__(self): del self.p diff --git a/tools/sim/bridge/common.py b/tools/sim/bridge/common.py index be1d7505a3..bbbfd9a981 100644 --- a/tools/sim/bridge/common.py +++ b/tools/sim/bridge/common.py @@ -47,12 +47,11 @@ class SimulatorBridge(ABC): self.dual_camera = dual_camera self.high_quality = high_quality - self._exit_event = threading.Event() + self._exit_event: threading.Event | None = None self._threads = [] self._keep_alive = True self.started = Value('i', False) signal.signal(signal.SIGTERM, self._on_shutdown) - self._exit = threading.Event() self.simulator_state = SimulatorState() self.world: World | None = None @@ -76,7 +75,9 @@ class SimulatorBridge(ABC): def close(self, reason): self.started.value = False - self._exit_event.set() + + if self._exit_event is not None: + self._exit_event.set() if self.world is not None: self.world.close(reason) @@ -103,6 +104,8 @@ Ignition: {self.simulator_state.ignition} Engaged: {self.simulator_state.is_enga self.simulated_car = SimulatedCar() self.simulated_sensors = SimulatedSensors(self.dual_camera) + self._exit_event = threading.Event() + self.simulated_car_thread = threading.Thread(target=rk_loop, args=(functools.partial(self.simulated_car.update, self.simulator_state), 100, self._exit_event)) self.simulated_car_thread.start()