mirror of https://github.com/commaai/openpilot.git
Make SimulatorBridge picklable (MacOS support) (#34023)
* remove unused * make Params (un)serializable * move initialization after spawn _thread.lock objects can't be pickled
This commit is contained in:
parent
50aac48fba
commit
dc73e6e2aa
|
@ -36,11 +36,16 @@ class UnknownKeyName(Exception):
|
|||
|
||||
cdef class Params:
|
||||
cdef c_Params* p
|
||||
cdef str d
|
||||
|
||||
def __cinit__(self, d=""):
|
||||
cdef string path = <string>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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue