Skip to content

Commit

Permalink
replace raise e w raise to maintain traceback - thanks botto
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmatthis committed Sep 6, 2024
1 parent 4239c4f commit ab97167
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 21 deletions.
1 change: 0 additions & 1 deletion skellycam-ui/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<NuxtPage/>
</v-app>
</NuxtLayout>

</template>


48 changes: 38 additions & 10 deletions skellycam/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# __main__.py
import argparse
import logging
import multiprocessing
import sys
Expand All @@ -14,40 +14,68 @@
PATH_TO_SKELLYCAM_MAIN = str(Path(__file__).absolute())


def main(qt_gui: bool = False):
def main(qt: bool = False) -> None:
"""
Main function to start the SkellyCam application.
Parameters
----------
qt : bool, optional
Whether to start the application with a Qt GUI (default is False)
"""
logger.info(f"Running from __main__: {__name__} - {clean_path(__file__)}")
if sys.platform == "win32":
setup_app_id_for_windows()
if qt_gui:

if qt:
from skellycam.gui.gui_main import gui_main
# multiprocessing.set_start_method("fork") # might be needed for MacOS or Linux?

shutdown_event = multiprocessing.Event()

frontend_process = multiprocessing.Process(target=gui_main, args=(shutdown_event,))
logger.info(f"Starting frontend process")
logger.info("Starting frontend process")
frontend_process.start()

backend_process = Process(target=run_server, args=(shutdown_event,))
logger.info(f"Starting backend process")
logger.info("Starting backend process")
backend_process.start()

frontend_process.join()
logger.info("Frontend process ended - terminating backend process")
shutdown_event.set()
backend_process.join()
logger.info(f"Exiting `main`...")
logger.info("Exiting `main`...")
else:
run_server()


if __name__ == "__main__":
"""
Entry point for the SkellyCam application.
This script can be run with or without a Qt GUI. By default, the application runs without the GUI.
To start the application with a Qt GUI, use the --qt flag.
Usage
-----
Without GUI:
python __main__.py
With GUI:
python __main__.py --qt
"""
multiprocessing.freeze_support()
parser = argparse.ArgumentParser(description="Start the SkellyCam application.")
parser.add_argument('--qt', action='store_true', default=False, help="Start the application with a Qt GUI.")
args = parser.parse_args()

try:
main(qt_gui=True)
main(qt=args.qt)
except KeyboardInterrupt:
logger.info("Keyboard interrupt - shutting down!")
except Exception:
raise Exception
except Exception as e:
logger.exception("An unexpected error occurred", exc_info=e)
raise
print("\n\n--------------------------------------------------\n--------------------------------------------------")
print("Thank you for using SkellyCam \U0001F480 \U0001F4F8 \U00002728 \U0001F495")
print("--------------------------------------------------\n--------------------------------------------------\n\n")
2 changes: 1 addition & 1 deletion skellycam/api/routes/websocket/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def websocket_relay(websocket: WebSocket):
logger.api("Client disconnected, ending listener task...")
except Exception as e:
logger.exception(f"Error in websocket relay: {e.__class__}: {e}")
raise e
raise
finally:
logger.info("Ending listener for frontend payload messages in queue...")

Expand Down
2 changes: 1 addition & 1 deletion skellycam/api/server/server_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def server_thread():
except Exception as e:
logger.error(f"A fatal error occurred in the uvicorn server: {e}")
logger.exception(e)
raise e
raise
finally:
logger.info(f"Shutting down uvicorn server")

Expand Down
2 changes: 1 addition & 1 deletion skellycam/core/cameras/group/camera_group_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _run_process(frontend_relay_pipe: multiprocessing.Pipe,
except Exception as e:
logger.error(f"CameraGroupProcess error: {e}")
logger.exception(e)
raise e
raise
finally:
kill_camera_group_flag.value = True
frame_wrangler.close() if frame_wrangler else None
Expand Down
2 changes: 1 addition & 1 deletion skellycam/core/frames/wrangling/frame_listener_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _run_process(camera_configs: CameraConfigs,
wait_1ms()
except Exception as e:
logger.exception(f"Frame listener process error: {e.__class__} - {e}")
raise e
raise
finally:
logger.trace(f"Stopped listening for multi-frames")
camera_group_shm.close() # close but don't unlink - parent process will unlink
Expand Down
2 changes: 1 addition & 1 deletion skellycam/core/frames/wrangling/frame_router_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _run_process(camera_configs: CameraConfigs,
except Exception as e:
logger.error(f"Frame exporter process error: {e}")
logger.exception(e)
raise e
raise
finally:
logger.trace(f"Stopped listening for multi-frames")
if video_recorder_manager:
Expand Down
2 changes: 1 addition & 1 deletion skellycam/core/timestamps/multiframe_timestamp_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _get_camera_stats(self, stats) -> Dict[Hashable, Dict[str, float]]:

except Exception as e:
logger.error(f"Error saving timestamp stats: {e}")
raise e
raise
return camera_stats_by_id

def _get_timestamp_stats(self) -> Dict[Hashable, Any]:
Expand Down
4 changes: 2 additions & 2 deletions skellycam/gui/client/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _on_message(self, ws: WebSocketApp, message: Union[str, bytes]) -> None:

def _on_error(self, ws: WebSocketApp, exception: Exception) -> None:
logger.exception(f"WebSocket exception: {exception.__class__.__name__}: {exception}")
raise exception
raise

def _on_close(self, ws: WebSocketApp, close_status_code, close_msg) -> None:
logger.info(f"WebSocket connection closed: Close status code: {close_status_code}, Close message: {close_msg}")
Expand Down Expand Up @@ -115,7 +115,7 @@ def _handle_json_message(self, message: Dict[str, Any]) -> None:
logger.info(f"Received JSON message, size: {len(json.dumps(message))} bytes")
except Exception as e:
logger.exception(e)
raise e
raise

def send_message(self, message: Union[str, bytes, Dict[str, Any]]) -> None:
if self.websocket:
Expand Down
2 changes: 1 addition & 1 deletion skellycam/gui/qt/widgets/camera_grid_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def clear_camera_views(self):
self._camera_landscape_grid_layout.removeWidget(single_camera_view)
except Exception as e:
logger.error(f"Error clearing camera layout dictionary: {e}")
raise e
raise

def set_image_data(self,
jpeg_images: Dict[CameraId, str],
Expand Down
2 changes: 1 addition & 1 deletion skellycam/utilities/find_available_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def find_available_port(start_port: int) -> int:
port += 1
if port > 65535: # No more ports available
logger.error("No ports available!")
raise e
raise

0 comments on commit ab97167

Please sign in to comment.