Skip to content

Commit

Permalink
Merge pull request #17 from mahenzon/hotfix/fix-cancelled-error-import
Browse files Browse the repository at this point in the history
hotfix #16 CancelledError import
  • Loading branch information
mahenzon committed Apr 17, 2022
2 parents af2e58f + 590818b commit 6d5d642
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions aioalice/dispatcher/webhook.py
@@ -1,12 +1,23 @@
import asyncio
import logging
import functools
import sys
from typing import TYPE_CHECKING

from aiohttp import web

from aioalice.utils import json, generate_json_payload
from aioalice.types import AliceRequest, AliceResponse, Response

if sys.version_info >= (3, 7):
from asyncio import CancelledError
else:
from asyncio.futures import CancelledError


if TYPE_CHECKING:
from aioalice import Dispatcher


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -46,7 +57,7 @@ class WebhookRequestHandler(web.View):
"""

def get_dispatcher(self):
def get_dispatcher(self) -> "Dispatcher":
"""
Get Dispatcher instance from environment
"""
Expand Down Expand Up @@ -74,7 +85,7 @@ async def process_request(self, request):
:param request:
:return:
"""
dispatcher = self.get_dispatcher()
dispatcher: "Dispatcher" = self.get_dispatcher()
loop = dispatcher.loop

# Analog of `asyncio.wait_for` but without cancelling task
Expand All @@ -88,7 +99,7 @@ async def process_request(self, request):
try:
try:
await waiter
except asyncio.futures.CancelledError:
except CancelledError:
fut.remove_done_callback(done_cb)
fut.cancel()
raise
Expand Down

0 comments on commit 6d5d642

Please sign in to comment.