def _render_timelapse(self, print_end_state): # make sure we have a non null TimelapseSettings object. We may have terminated the timelapse for some reason if self.Rendering is not None and self.Rendering.enabled: self.Settings.current_debug_profile().log_render_start("Started Rendering Timelapse") # we are rendering, set the state before starting the rendering job. timelapse_render_job = Render( self.Settings, self.Snapshot, self.Rendering, self.DataFolder, self.DefaultTimelapseDirectory, self.FfMpegPath, 1, time_added=self.SecondsAddedByOctolapse, on_render_start=self._on_render_start, on_render_fail=self._on_render_fail, on_render_success=self._on_render_success, on_render_complete=self.on_render_complete, on_after_sync_fail=self._on_synchronize_rendering_fail, on_after_sync_success=self._on_synchronize_rendering_complete, on_complete=self._on_render_end ) job_id = "TimelapseRenderJob_{0}".format(str(uuid.uuid4())) self.RenderingJobs.add(job_id) try: timelapse_render_job.process(job_id, utility.get_currently_printing_filename( self.OctoprintPrinter), self.PrintStartTime, time.time(), print_end_state) return True except Exception as e: self.Settings.current_debug_profile().log_exception(e) self.RenderingJobs.remove(job_id) return False
def _take_snapshot_async(self): snapshot_async_payload = {"success": False, "error": ""} if self._snapshot_signal.is_set(): # only clear signal and send a new M114 if we haven't already done that from another thread self._snapshot_signal.clear() # start the snapshot self.Settings.current_debug_profile().log_snapshot_download( "Taking a snapshot.") try: self.CaptureSnapshot.snap( utility.get_currently_printing_filename( self.OctoprintPrinter), self.SnapshotCount, on_success=self._on_snapshot_success, on_fail=self._on_snapshot_fail) self._snapshot_signal.wait(self._snapshot_timeout) if not self._snapshot_signal.is_set(): # we ran into a timeout while waiting for a fresh position snapshot_async_payload["error"] = \ "Snapshot timed out in {0} seconds.".format(self._snapshot_timeout) return snapshot_async_payload snapshot_async_payload["success"] = True return self._snapshot_success except Exception as e: self.Settings.current_debug_profile().log_exception(e) snapshot_async_payload[ "error"] = "An unexpected error was encountered while taking a snapshot" return snapshot_async_payload
def _render_timelapse(self, print_end_state): def _render_timelapse_async(render_job_id, timelapse_render_job): try: snapshot_thread = threading.Thread(target=timelapse_render_job, args=[]) snapshot_thread.daemon = True num_snapshot_tasks = self._snapshot_task_queue.qsize() if num_snapshot_tasks > 0: self.Settings.current_debug_profile().log_render_start("Started Rendering Timelapse.") else: self.Settings.current_debug_profile().log_render_start( "Waiting for {0} snapshot threads to complete".format( self._snapshot_task_queue.qsize())) self._snapshot_task_queue.join() self.Settings.current_debug_profile().log_render_start( "All snapshot tasks have completed, rendering timelapse" ) # we are rendering, set the state before starting the rendering job. self._rendering_task_queue.put(render_job_id) snapshot_thread.start() except Exception as e: self.Settings.current_debug_profile().log_exception(e) self._rendering_task_queue.get() self._rendering_task_queue.task_done() # make sure we have a non null TimelapseSettings object. We may have terminated the timelapse for some reason if self.Rendering is not None and self.Rendering.enabled: job_id = "TimelapseRenderJob_{0}".format(str(uuid.uuid4())) job = Render.create_render_job( self.Settings, self.Snapshot, self.Rendering, self.DataFolder, self.DefaultTimelapseDirectory, self.FfMpegPath, 1, self._rendering_task_queue, job_id, utility.get_currently_printing_filename(self.OctoprintPrinter), self.PrintStartTime, time.time(), print_end_state, self.SecondsAddedByOctolapse, self._on_render_start, self._on_render_end ) rendering_thread = threading.Thread(target=_render_timelapse_async, args=[job_id, job]) rendering_thread.daemon = True rendering_thread.start() return True return False
def _take_snapshot_async(self): snapshot_async_payload = { "success": False, "error": "Waiting on thread to signal, aborting" } if self._snapshot_signal.is_set(): # only clear signal and send a new M114 if we haven't already done that from another thread self._snapshot_signal.clear() # start the snapshot self.Settings.current_debug_profile().log_snapshot_download("Taking a snapshot.") snapshot_guid = str(uuid.uuid4()) snapshot_job = self.CaptureSnapshot.create_snapshot_job( utility.get_currently_printing_filename(self.OctoprintPrinter), self.SnapshotCount, snapshot_guid, self._snapshot_task_queue, on_success=self._on_snapshot_success, on_fail=self._on_snapshot_fail, on_complete=self._on_snapshot_complete ) self._snapshot_task_queue.put(snapshot_guid) snapshot_thread = threading.Thread(target=snapshot_job) snapshot_thread.daemon = True snapshot_thread.start() event_is_set = self._snapshot_signal.wait(self._snapshot_timeout) if not event_is_set: # we ran into a timeout while waiting for a fresh position snapshot_async_payload["success"] = False snapshot_async_payload["error"] = \ "Snapshot timed out in {0} seconds.".format(self._snapshot_timeout) self._snapshot_signal.set() else: snapshot_async_payload["success"] = True return snapshot_async_payload