Skip to content

Alternative to passing router to the application? #11840

@mcfletch

Description

@mcfletch

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

DeprecationWarning: router argument is deprecated

Python Version

$ python --version
Python 3.11.14

aiohttp Version

$ 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

$ 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: [email protected]
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

$ 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: [email protected]
License: Apache-2.0
Location: /home/mcfletch/atx-dev/vada-devsetup/.venv/lib/python3.11/site-packages
Requires: 
Required-by: aiohttp, yarl

yarl Version

$ 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: [email protected]
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

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions