diff --git a/klippy/klippy.py b/klippy/klippy.py index 3d090886..187b45e5 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -48,10 +48,10 @@ Printer is shutdown class Printer: config_error = configfile.error command_error = homing.CommandError - def __init__(self, bglogger, start_args): + def __init__(self, main_reactor, bglogger, start_args): self.bglogger = bglogger self.start_args = start_args - self.reactor = reactor.Reactor() + self.reactor = main_reactor self.reactor.register_callback(self._connect) self.state_message = message_startup self.in_shutdown_state = False @@ -312,11 +312,13 @@ def main(): if bglogger is not None: bglogger.clear_rollover_info() bglogger.set_rollover_info('versions', versions) - printer = Printer(bglogger, start_args) + main_reactor = reactor.Reactor() + printer = Printer(main_reactor, bglogger, start_args) res = printer.run() if res in ['exit', 'error_exit']: break time.sleep(1.) + main_reactor.finalize() logging.info("Restarting printer") start_args['start_reason'] = res diff --git a/klippy/reactor.py b/klippy/reactor.py index 07c7db19..e38d4fd9 100644 --- a/klippy/reactor.py +++ b/klippy/reactor.py @@ -178,11 +178,6 @@ class SelectReactor: util.set_nonblock(self._pipe_fds[0]) util.set_nonblock(self._pipe_fds[1]) self.register_fd(self._pipe_fds[0], self._got_pipe_signal) - def __del__(self): - if self._pipe_fds is not None: - os.close(self._pipe_fds[0]) - os.close(self._pipe_fds[1]) - self._pipe_fds = None # Greenlets def _sys_pause(self, waketime): # Pause using system sleep for when reactor not running @@ -251,6 +246,11 @@ class SelectReactor: g_next.switch() def end(self): self._process = False + def finalize(self): + if self._pipe_fds is not None: + os.close(self._pipe_fds[0]) + os.close(self._pipe_fds[1]) + self._pipe_fds = None class PollReactor(SelectReactor): def __init__(self):