Alternative to passing router to the application?
- Lingua principale
- Python
- Stelle
- 16.5k
- Fork
- 2.4k
- Merge medio
- 20h 10m
- PR unite (30g)
- 221
Descrizione
### Describe the bug
I have an application which can discover new plugins at run time (think plugging new hardware into a generic backplane). As such, the routing of the application can change based on which hardware has been inserted after the application is running. There are lots of long-running (websocket) processes, so I don't want to restart the application just to allow the new endpoints to be registered.
My solution so far has been to create a router facade which tracks each registered endpoint and generates a new standard router with those endpoints when there's an update to the set of plugged in hardware and swaps in the router to handle new requests without cycling the application or listening port. That works fine, but apparently the Application's `router` argument is now deprecated.
Is there a recommended solution for those who *do* use custom routers with aiohttp? Should we sub-class Application to override the class used to create the router?
### To Reproduce
1. Attempt to pass router to the Application
2. Deprecation warning is generated
### Expected behavior
There would ideally be a straightforward way for those who have coded custom routers to be able to use them with the newer releases of aiohttp.
### Logs/tracebacks
```python-traceback
DeprecationWarning: router argument is deprecated
```
### Python Version
```console
$ python --version
Python 3.11.14
```
### aiohttp Version
```console
$ python -m pip show aiohttp
Name: aiohttp
Version: 3.13.1
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache-2.0 AND MIT
Location: /home/mcfletch/atx-dev/vada-devsetup/.venv/lib/python3.11/site-packages
Requires: aiohappyeyeballs, aiosignal, attrs, frozenlist, multidict, propcache, yarl
Required-by: aiohttp-swagger, aiosseclient
```
### multidict Version
```console
$ python -m pip show multidict
Name: multidict
Version: 6.7.0
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache License 2.0
Location: /home/mcfletch/atx-dev/vada-devsetup/.venv/lib/python3.11/site-packages
Requires:
Required-by: aiohttp, grpclib, yarl
```
### propcache Version
```console
$ python -m pip show propcache
Name: propcache
Version: 0.4.1
Summary: Accelerated property cache
Home-page: https://github.com/aio-libs/propcache
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /home/mcfletch/atx-dev/vada-devsetup/.venv/lib/python3.11/site-packages
Requires:
Required-by: aiohttp, yarl
```
### yarl Version
```console
$ python -m pip show yarl
Name: yarl
Version: 1.22.0
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /home/mcfletch/atx-dev/vada-devsetup/.venv/lib/python3.11/site-packages
Requires: idna, multidict, propcache
Required-by: aiohttp
```
### OS
Debian, Ubuntu, Yocto
### Related component
Server
### Additional context
_No response_
### Code of Conduct
- [x] I agree to follow the aio-libs Code of Conduct
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.