-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert entire image proxy route async (#3388)
* Convert entire image proxy route async * Update tests for async implementation * Remove duplicated fixture * Use clearer name for await avoidance function * Clean up documentation * Remove unused import
- Loading branch information
1 parent
adb56f1
commit 401cb8e
Showing
7 changed files
with
187 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import asyncio | ||
import logging | ||
from collections.abc import Awaitable | ||
|
||
|
||
parent_logger = logging.getLogger(__name__) | ||
|
||
|
||
_do_not_wait_for_logger = parent_logger.getChild("do_not_wait_for") | ||
|
||
|
||
def do_not_wait_for(awaitable: Awaitable) -> None: | ||
""" | ||
Consume an awaitable without waiting for it to finish. | ||
This allows us to call an async function that we don't care about | ||
the result of, without needing to wait for it to complete. This is | ||
useful, for example, if some operation creates a side effect that | ||
isn't necessary for the response we're processing (e.g., Redis tallying). | ||
""" | ||
try: | ||
loop = asyncio.get_running_loop() | ||
except RuntimeError as exc: | ||
_do_not_wait_for_logger.error( | ||
"`do_not_wait_for` must be called inside a running event loop." | ||
) | ||
raise exc | ||
|
||
loop.create_task(awaitable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.