diff --git a/app.log b/app.log new file mode 100644 index 0000000..0866815 --- /dev/null +++ b/app.log @@ -0,0 +1,601 @@ +2025-01-09 00:43:08,967 [INFO] Will watch for changes in these directories: ['/Users/siwatsirichai/Documents/GitHub/python-detector-worker'] +2025-01-09 00:43:08,967 [INFO] Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +2025-01-09 00:43:08,967 [INFO] Started reloader process [36467] using WatchFiles +2025-01-09 00:43:09,356 [INFO] 1 change detected +2025-01-09 00:43:10,532 [INFO] Started server process [36471] +2025-01-09 00:43:10,534 [INFO] Waiting for application startup. +2025-01-09 00:43:10,534 [INFO] Application startup complete. +2025-01-09 00:43:17,203 [INFO] WebSocket connection accepted +2025-01-09 00:43:17,205 [INFO] ('127.0.0.1', 59148) - "WebSocket /" [accepted] +2025-01-09 00:43:17,207 [INFO] connection open +2025-01-09 00:43:17,207 [INFO] Started processing streams +2025-01-09 00:43:23,325 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:44:48,212 [INFO] 1 change detected +2025-01-09 00:44:48,217 [WARNING] WatchFiles detected changes in 'app.py'. Reloading... +2025-01-09 00:44:48,227 [INFO] Shutting down +2025-01-09 00:44:48,239 [ERROR] Error in WebSocket connection: (1012, None) +2025-01-09 00:44:48,255 [INFO] Released camera camera1 +2025-01-09 00:44:48,255 [INFO] WebSocket connection closed +2025-01-09 00:44:48,256 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 102, in detect + streams.clear() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:44:48,323 [INFO] connection closed +2025-01-09 00:44:48,333 [INFO] Waiting for application shutdown. +2025-01-09 00:44:48,334 [INFO] Application shutdown complete. +2025-01-09 00:44:48,335 [INFO] Finished server process [36471] +2025-01-09 00:44:48,728 [INFO] 1 change detected +2025-01-09 00:44:51,790 [INFO] Started server process [36622] +2025-01-09 00:44:51,793 [INFO] Waiting for application startup. +2025-01-09 00:44:51,794 [INFO] Application startup complete. +2025-01-09 00:44:52,764 [INFO] WebSocket connection accepted +2025-01-09 00:44:52,764 [INFO] ('127.0.0.1', 59328) - "WebSocket /" [accepted] +2025-01-09 00:44:52,765 [INFO] connection open +2025-01-09 00:44:52,766 [INFO] Started processing streams +2025-01-09 00:44:59,314 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:45:23,328 [ERROR] Error in WebSocket connection: (, '') +2025-01-09 00:45:23,354 [INFO] Released camera camera1 +2025-01-09 00:45:23,354 [INFO] WebSocket connection closed +2025-01-09 00:45:23,356 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 104, in detect + await websocket.close() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:45:23,433 [INFO] connection closed +2025-01-09 00:45:25,088 [INFO] WebSocket connection accepted +2025-01-09 00:45:25,088 [INFO] ('127.0.0.1', 59396) - "WebSocket /" [accepted] +2025-01-09 00:45:25,091 [INFO] connection open +2025-01-09 00:45:25,092 [INFO] Started processing streams +2025-01-09 00:45:31,313 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:45:37,901 [INFO] Shutting down +2025-01-09 00:45:37,906 [ERROR] Error in WebSocket connection: (1012, None) +2025-01-09 00:45:37,919 [INFO] Released camera camera1 +2025-01-09 00:45:37,919 [INFO] WebSocket connection closed +2025-01-09 00:45:37,919 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 104, in detect + await websocket.close() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:45:37,921 [INFO] connection closed +2025-01-09 00:45:38,006 [INFO] Waiting for application shutdown. +2025-01-09 00:45:38,007 [INFO] Application shutdown complete. +2025-01-09 00:45:38,008 [INFO] Finished server process [36622] +2025-01-09 00:45:38,031 [INFO] Stopping reloader process [36467] +2025-01-09 00:46:40,345 [INFO] Will watch for changes in these directories: ['/Users/siwatsirichai/Documents/GitHub/python-detector-worker'] +2025-01-09 00:46:40,346 [INFO] Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +2025-01-09 00:46:40,347 [INFO] Started reloader process [36868] using WatchFiles +2025-01-09 00:46:42,402 [INFO] Started server process [36902] +2025-01-09 00:46:42,404 [INFO] Waiting for application startup. +2025-01-09 00:46:42,405 [INFO] Application startup complete. +2025-01-09 00:46:42,439 [INFO] WebSocket connection accepted +2025-01-09 00:46:42,439 [INFO] ('127.0.0.1', 59523) - "WebSocket /" [accepted] +2025-01-09 00:46:42,440 [INFO] connection open +2025-01-09 00:46:42,440 [INFO] Started processing streams +2025-01-09 00:46:47,311 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:46:51,990 [ERROR] Error in WebSocket connection: (, '') +2025-01-09 00:46:52,001 [INFO] Released camera camera1 +2025-01-09 00:46:52,002 [INFO] WebSocket connection closed +2025-01-09 00:46:52,002 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 104, in detect + await websocket.close() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:46:52,030 [INFO] connection closed +2025-01-09 00:47:56,615 [INFO] WebSocket connection accepted +2025-01-09 00:47:56,616 [INFO] ('127.0.0.1', 59664) - "WebSocket /" [accepted] +2025-01-09 00:47:56,628 [INFO] connection open +2025-01-09 00:47:56,631 [INFO] Started processing streams +2025-01-09 00:48:03,306 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:48:06,345 [ERROR] Error in WebSocket connection: (, '') +2025-01-09 00:48:06,352 [INFO] Released camera camera1 +2025-01-09 00:48:06,352 [INFO] WebSocket connection closed +2025-01-09 00:48:06,353 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 104, in detect + await websocket.close() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:48:06,361 [INFO] connection closed +2025-01-09 00:48:38,544 [INFO] WebSocket connection accepted +2025-01-09 00:48:38,545 [INFO] ('127.0.0.1', 59735) - "WebSocket /" [accepted] +2025-01-09 00:48:38,546 [INFO] connection open +2025-01-09 00:48:38,550 [INFO] Started processing streams +2025-01-09 00:48:43,303 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:49:28,103 [ERROR] Error in WebSocket connection: (, '') +2025-01-09 00:49:28,115 [INFO] Released camera camera1 +2025-01-09 00:49:28,116 [INFO] WebSocket connection closed +2025-01-09 00:49:28,116 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 104, in detect + await websocket.close() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:49:28,125 [INFO] connection closed +2025-01-09 00:50:30,615 [INFO] WebSocket connection accepted +2025-01-09 00:50:30,616 [INFO] ('127.0.0.1', 59919) - "WebSocket /" [accepted] +2025-01-09 00:50:30,618 [INFO] connection open +2025-01-09 00:50:30,619 [INFO] Started processing streams +2025-01-09 00:50:35,299 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:51:20,717 [ERROR] Error in WebSocket connection: (, '') +2025-01-09 00:51:20,727 [INFO] Released camera camera1 +2025-01-09 00:51:20,727 [INFO] WebSocket connection closed +2025-01-09 00:51:20,727 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 104, in detect + await websocket.close() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:51:20,732 [INFO] connection closed +2025-01-09 00:52:20,552 [INFO] 1 change detected +2025-01-09 00:52:20,571 [WARNING] WatchFiles detected changes in 'app.py'. Reloading... +2025-01-09 00:52:20,681 [INFO] Shutting down +2025-01-09 00:52:20,787 [INFO] Waiting for application shutdown. +2025-01-09 00:52:20,790 [INFO] Application shutdown complete. +2025-01-09 00:52:20,791 [INFO] Finished server process [36902] +2025-01-09 00:52:21,170 [INFO] 1 change detected +2025-01-09 00:52:23,436 [INFO] Started server process [37369] +2025-01-09 00:52:23,438 [INFO] Waiting for application startup. +2025-01-09 00:52:23,438 [INFO] Application startup complete. +2025-01-09 00:52:54,852 [INFO] 1 change detected +2025-01-09 00:52:54,860 [WARNING] WatchFiles detected changes in 'app.py'. Reloading... +2025-01-09 00:52:54,949 [INFO] Shutting down +2025-01-09 00:52:55,052 [INFO] Waiting for application shutdown. +2025-01-09 00:52:55,053 [INFO] Application shutdown complete. +2025-01-09 00:52:55,053 [INFO] Finished server process [37369] +2025-01-09 00:52:55,426 [INFO] 1 change detected +2025-01-09 00:52:57,074 [INFO] Started server process [37436] +2025-01-09 00:52:57,076 [INFO] Waiting for application startup. +2025-01-09 00:52:57,078 [INFO] Application startup complete. +2025-01-09 00:53:06,378 [INFO] 1 change detected +2025-01-09 00:53:08,915 [INFO] Shutting down +2025-01-09 00:53:09,018 [INFO] Waiting for application shutdown. +2025-01-09 00:53:09,020 [INFO] Application shutdown complete. +2025-01-09 00:53:09,021 [INFO] Finished server process [37436] +2025-01-09 00:53:09,044 [INFO] Stopping reloader process [36868] +2025-01-09 00:53:11,752 [INFO] Will watch for changes in these directories: ['/Users/siwatsirichai/Documents/GitHub/python-detector-worker'] +2025-01-09 00:53:11,753 [INFO] Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +2025-01-09 00:53:11,753 [INFO] Started reloader process [37483] using WatchFiles +2025-01-09 00:53:13,520 [INFO] Started server process [37487] +2025-01-09 00:53:13,522 [INFO] Waiting for application startup. +2025-01-09 00:53:13,523 [INFO] Application startup complete. +2025-01-09 00:53:14,050 [INFO] WebSocket connection accepted +2025-01-09 00:53:14,050 [INFO] ('127.0.0.1', 60224) - "WebSocket /" [accepted] +2025-01-09 00:53:14,052 [INFO] connection open +2025-01-09 00:53:14,052 [INFO] Started processing streams +2025-01-09 00:53:19,283 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:53:36,514 [INFO] 1 change detected +2025-01-09 00:53:38,902 [ERROR] Error in WebSocket connection: (, '') +2025-01-09 00:53:38,910 [INFO] Released camera camera1 +2025-01-09 00:53:38,911 [INFO] WebSocket connection closed +2025-01-09 00:53:38,911 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 111, in detect + await websocket.close() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:53:38,944 [INFO] connection closed +2025-01-09 00:53:40,757 [INFO] Shutting down +2025-01-09 00:53:40,880 [INFO] Finished server process [37487] +2025-01-09 00:53:40,980 [ERROR] Traceback (most recent call last): + File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run + return loop.run_until_complete(main) + File "uvloop/loop.pyx", line 1512, in uvloop.loop.Loop.run_until_complete + File "uvloop/loop.pyx", line 1505, in uvloop.loop.Loop.run_until_complete + File "uvloop/loop.pyx", line 1379, in uvloop.loop.Loop.run_forever + File "uvloop/loop.pyx", line 557, in uvloop.loop.Loop._run + File "uvloop/loop.pyx", line 476, in uvloop.loop.Loop._on_idle + File "uvloop/cbhandles.pyx", line 83, in uvloop.loop.Handle._run + File "uvloop/cbhandles.pyx", line 63, in uvloop.loop.Handle._run + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/server.py", line 70, in serve + await self._serve(sockets) + File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/contextlib.py", line 124, in __exit__ + next(self.gen) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/server.py", line 330, in capture_signals + signal.raise_signal(captured_signal) +KeyboardInterrupt + +During handling of the above exception, another exception occurred: + +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 700, in lifespan + await receive() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/lifespan/on.py", line 137, in receive + return await self.receive_queue.get() + File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/queues.py", line 166, in get + await getter +asyncio.exceptions.CancelledError + +2025-01-09 00:53:41,696 [INFO] Stopping reloader process [37483] +2025-01-09 00:53:46,103 [INFO] Will watch for changes in these directories: ['/Users/siwatsirichai/Documents/GitHub/python-detector-worker'] +2025-01-09 00:53:46,103 [INFO] Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +2025-01-09 00:53:46,104 [INFO] Started reloader process [37591] using WatchFiles +2025-01-09 00:53:47,860 [INFO] Started server process [37599] +2025-01-09 00:53:47,862 [INFO] Waiting for application startup. +2025-01-09 00:53:47,862 [INFO] Application startup complete. +2025-01-09 00:54:51,976 [INFO] Shutting down +2025-01-09 00:54:52,080 [INFO] Waiting for application shutdown. +2025-01-09 00:54:52,083 [INFO] Application shutdown complete. +2025-01-09 00:54:52,083 [INFO] Finished server process [37599] +2025-01-09 00:54:52,102 [INFO] Stopping reloader process [37591] +2025-01-09 00:54:54,952 [INFO] Will watch for changes in these directories: ['/Users/siwatsirichai/Documents/GitHub/python-detector-worker'] +2025-01-09 00:54:54,953 [INFO] Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +2025-01-09 00:54:54,953 [INFO] Started reloader process [37680] using WatchFiles +2025-01-09 00:54:56,634 [INFO] Started server process [37693] +2025-01-09 00:54:56,636 [INFO] Waiting for application startup. +2025-01-09 00:54:56,636 [INFO] Application startup complete. +2025-01-09 00:54:56,882 [INFO] WebSocket connection accepted +2025-01-09 00:54:56,882 [INFO] ('127.0.0.1', 60381) - "WebSocket /" [accepted] +2025-01-09 00:54:56,884 [INFO] connection open +2025-01-09 00:54:56,885 [INFO] Started processing streams +2025-01-09 00:55:03,279 [INFO] Subscribed to camera camera1 with URL rtsp://192.168.0.66:8554/common_room +2025-01-09 00:55:13,896 [ERROR] Error in WebSocket connection: (, '') +2025-01-09 00:55:13,907 [INFO] Released camera camera1 +2025-01-09 00:55:13,908 [INFO] WebSocket connection closed +2025-01-09 00:55:13,908 [ERROR] Exception in ASGI application +Traceback (most recent call last): + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi + result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__ + return await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/applications.py", line 1054, in __call__ + await super().__call__(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 113, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 152, in __call__ + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ + await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 715, in __call__ + await self.middleware_stack(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 735, in app + await route.handle(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 362, in handle + await self.app(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 95, in app + await wrap_app_handling_exceptions(app, session)(scope, receive, send) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app + raise exc + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app + await app(scope, receive, sender) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 93, in app + await func(session) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/fastapi/routing.py", line 383, in app + await dependant.call(**solved_result.values) + File "/Users/siwatsirichai/Documents/GitHub/python-detector-worker/app.py", line 111, in detect + await websocket.close() + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 180, in close + await self.send({"type": "websocket.close", "code": code, "reason": reason or ""}) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/websockets.py", line 85, in send + await self._send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/starlette/_exception_handler.py", line 39, in sender + await send(message) + File "/Users/siwatsirichai/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 359, in asgi_send + raise RuntimeError(msg % message_type) +RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close' or response already completed. +2025-01-09 00:55:13,943 [INFO] connection closed +2025-01-09 00:55:14,603 [INFO] Shutting down +2025-01-09 00:55:14,704 [INFO] Waiting for application shutdown. +2025-01-09 00:55:14,705 [INFO] Application shutdown complete. +2025-01-09 00:55:14,705 [INFO] Finished server process [37693] +2025-01-09 00:55:14,721 [INFO] Stopping reloader process [37680] diff --git a/app.py b/app.py index f4ecaa1..f8894fa 100644 --- a/app.py +++ b/app.py @@ -4,6 +4,8 @@ import torch import cv2 import base64 import numpy as np +import json +import logging app = FastAPI() @@ -11,26 +13,99 @@ model = YOLO("yolov8n.pt") if torch.cuda.is_available(): model.to('cuda') -@app.websocket("/detect") +with open("config.json", "r") as f: + config = json.load(f) + +poll_interval = config.get("poll_interval_ms", 100) +TARGET_FPS = config.get("target_fps", 10) # Add TARGET_FPS +poll_interval = 1000 / TARGET_FPS # Adjust poll_interval based on TARGET_FPS +logging.info(f"Poll interval: {poll_interval}ms") +max_streams = config.get("max_streams", 5) + +# Configure logging +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s [%(levelname)s] %(message)s", + handlers=[ + logging.FileHandler("app.log"), + logging.StreamHandler() + ] +) + +@app.websocket("/") async def detect(websocket: WebSocket): + import asyncio + import time + + logging.info("WebSocket connection accepted") + + # Move streams inside the detect function + streams = {} + + async def process_streams(): + logging.info("Started processing streams") + while True: + start_time = time.time() + # Round-robin processing + for camera_id, cap in list(streams.items()): + logging.debug(f"Processing camera: {camera_id}") + ret, frame = cap.read() + if not ret: + logging.warning(f"Failed to read frame from camera: {camera_id}") + continue + results = model(frame, stream=False) + boxes = [] + for r in results: + for box in r.boxes: + boxes.append({ + "class": int(box.cls[0]), + "confidence": float(box.conf[0]), + }) + # Broadcast to all subscribers of this URL + detection_data = { + "type": "imageDetection", + "cameraIdentifier": camera_id, + "timestamp": time.time(), + "data": { + "detections": boxes + } + } + logging.debug(f"Sending detection data for camera {camera_id}: {detection_data}") + await websocket.send_json(detection_data) + elapsed_time = (time.time() - start_time) * 1000 # in ms + sleep_time = max(poll_interval - elapsed_time, 0) + logging.debug(f"Elapsed time: {elapsed_time}ms, sleeping for: {sleep_time}ms") + await asyncio.sleep(sleep_time / 1000.0) + await websocket.accept() + task = asyncio.create_task(process_streams()) + try: while True: - data = await websocket.receive_text() - # Decode base64 image bytes - img_data = base64.b64decode(data) - np_arr = np.frombuffer(img_data, np.uint8) - frame = cv2.imdecode(np_arr, cv2.IMREAD_COLOR) + msg = await websocket.receive_text() + logging.debug(f"Received message: {msg}") + data = json.loads(msg) + camera_id = data.get("cameraIdentifier") + rtsp_url = data.get("rtspUrl") - results = model(frame, stream=False) - boxes = [] - for r in results: - for box in r.boxes: - boxes.append({ - "class": int(box.cls[0]), - "confidence": float(box.conf[0]), - }) - - await websocket.send_json({"detections": boxes}) - except: - pass + if camera_id and rtsp_url: + if camera_id not in streams and len(streams) < max_streams: + streams[camera_id] = cv2.VideoCapture(rtsp_url) + logging.info(f"Subscribed to camera {camera_id} with URL {rtsp_url}") + elif camera_id and camera_id in streams: + cap = streams.pop(camera_id) + cap.release() + logging.info(f"Unsubscribed from camera {camera_id}") + elif data.get("command") == "stop": + logging.info("Received stop command") + break + except Exception as e: + logging.error(f"Error in WebSocket connection: {e}") + finally: + task.cancel() + for camera_id, cap in streams.items(): + cap.release() + logging.info(f"Released camera {camera_id}") + streams.clear() + logging.info("WebSocket connection closed") + await websocket.close() diff --git a/config.json b/config.json new file mode 100644 index 0000000..53b0229 --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "poll_interval_ms": 100, + "max_streams": 5, + "target_fps": 0.5 +} diff --git a/requirements.txt b/requirements.txt index 2122d86..46a2624 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ uvicorn torch torchvision ultralytics -opencv-python +opencv-python \ No newline at end of file diff --git a/yolov8n.pt b/yolov8n.pt new file mode 100644 index 0000000..0db4ca4 Binary files /dev/null and b/yolov8n.pt differ