-
-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal]: Deprecate on_startup
and on_shutdown
in favor of lifespan
#397
Labels
ENHANCEMENT ⚡
New Feature/Addition/Improvement
PROPOSAL 📩
A proposal/proposition
SOLVED 🏁
This issue/PR is resolved now. Goal Achieved!
Projects
Milestone
Comments
abhiTronix
added
ENHANCEMENT ⚡
New Feature/Addition/Improvement
WORK IN PROGRESS 🚧
currently been worked on.
PROPOSAL 📩
A proposal/proposition
labels
May 15, 2024
6 tasks
6 tasks
abhiTronix
added a commit
that referenced
this issue
May 20, 2024
- 🏗️ Replaced deprecated Starlette's `on_shutdown` parameter with an async context manager `lifespan` in WebGear and WebGear_RTC APIs. - 🚚 Moved shutdown logic for VideoGear and peer RTC connections to this new `lifespan` context manager. - 📦️ Added new `contextlib` import for using `asynccontextmanager`. ### NetGear_Async API: - 🩹 Fixed event loop handling - ⚡️Modified `__init__` method to handle event loop more robustly: - Try to get the running event loop using `asyncio.get_running_loop()` - If no running event loop found, create a new one with `asyncio.new_event_loop()` - Log if creating a new event loop - 🧑💻 Changed launch method to use `self.loop.create_task()` instead of `asyncio.ensure_future()` - Ensures the task is created using the correct event loop instance. - 🚑️ Fix event loop initialization on Windows platforms - ⚡️ Moved the event loop initialization code to an earlier point before setting event loop policy to ensure it is set up correctly before selecting `WindowsSelectorEventLoop` policy. - 💬 Background: On Windows, vidgear requires the `WindowsSelectorEventLoop`, but Python 3.8 and above defaults to the `ProactorEventLoop` which is not compatible. - 🔥 Removed redundant python version check to set `WindowsSelectorEventLoop` policy, as minimum supported version is already `3.8`. - 💡 Updated code comments. - ⚡️ Move event loop setup and policy assignment to the beginning of `__init__` before zmq Context creation. ### PiGear API: - 🚑️ Modify PiGear class behavior when `enforce_legacy_picamera=True` on unsupported system - ⚡️ Instead of silently disabling `picamera2` API directly, PiGear now raises an error if `picamera` is unavailable or unsupported - 🥅 Prevented incorrect initialization of `PiGear` class on unsupported 64-bit OS systems. ### Docs: - 📝 Added workaround for 'AttributeError: 'DXCamera' object has no attribute 'is_capturing'' error on Windows. - 💄 Added new `screengear_error11.png` asset. - 📝 Update README.md with changes to JPEG compression options - ✏️ Replaces deprecated options (`frame_jpeg_quality`, `frame_jpeg_optimize`, `frame_jpeg_progressive`) with their newer equivalents (`jpeg_compression_quality,` `jpeg_compression_fastdct`, `jpeg_compression_fastupsample`) in WebGear usage example. - 🐛 Replaced buggy kofi widget with a button image in index.md - 🏗️ Remove script tags from main.html and use a custom hook for adding JS - 🔥 Remove site.webmanifest file - 💄 Update mkdocs.yml with new configuration settings: - Set edit_uri for GitHub edit links - Add new theme features like content actions, tooltips, etc. - Update palette settings for light/dark mode - Enable new markdown extensions - Add custom JS hook for adding scripts on certain pages - ♻️ Other minor tweaks and cleanups - 🧑💻 Refactored all APIs and bonus examples to use linenums and hl_lines - Makes it easier to highlight specific lines in code blocks - 📝 Updated remaining code examples for picamera2 and legacy picamera backends - 🐛 Replaced buggy kofi widget with a button image in `help.md` - 💄 Update announcement icon in `main.html` - 💄 Change system mode toggle icon and name in `mkdocs.yml` - 📝 Add failure warning in various docs about `picamera` incompatibility on 64-bit OS ### CI: - 💚 Deprecated event_loop fixture overrides. - 👷 Added new recommended approach of using `pytest.mark.asyncio(scope="module")` to mark all WebGear_RTC and NetGear_Async tests as asynchronous and utilize the same event loop throughout the module. - 🗑️ Deprecated custom `event_loop` fixture overrides in WebGear_RTC and NetGear_Async tests. - 🔥 Removed redundant `pytest.mark.asyncio` decorators from several test functions. - 💚 Refactor event loop handling - 👷 Add a new event_loop_policy fixture for pytest to override the event loop policy - 🔊 Log the event loop being used for debugging - 🔧 Mark the new fixture in relevant test functions with pytest.mark.asyncio(scope="module") - ♻️ Remove unused imports and code cleanup
Successfully fixed in commit 20dec0a |
abhiTronix
added
SOLVED 🏁
This issue/PR is resolved now. Goal Achieved!
and removed
WORK IN PROGRESS 🚧
currently been worked on.
labels
May 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ENHANCEMENT ⚡
New Feature/Addition/Improvement
PROPOSAL 📩
A proposal/proposition
SOLVED 🏁
This issue/PR is resolved now. Goal Achieved!
Issue guidelines
Issue Checklist
Describe your Idea
Currently, Starlette supports
on_startup
andon_shutdown
hooks for running startup and shutdown tasks. However, these hooks have certain limitations and are not as robust as thelifespan
approach, which uses async context managers.Use Cases
The
lifespan
approach provides a more structured and reliable way to handle startup and shutdown tasks, and it is recommended by the ASGI specification (https://asgi.readthedocs.io/en/latest/specs/lifespan.html). This proposal aligns with the ASGI specification and promotes best practices for handling startup and shutdown tasks in Starlette applications in our APIs such as WebGear and WebGear_RTC which uses it.Any other Relevant Information?
Related Issues:
The text was updated successfully, but these errors were encountered: