Skip to content

Replace asyncio.iscoroutinefunction with inspect.iscoroutinefunction #387

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/engineio/async_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import signal
import ssl
import threading
Expand Down Expand Up @@ -456,7 +457,7 @@ async def _trigger_event(self, event, *args, **kwargs):
run_async = kwargs.pop('run_async', False)
ret = None
if event in self.handlers:
if asyncio.iscoroutinefunction(self.handlers[event]) is True:
if inspect.iscoroutinefunction(self.handlers[event]) is True:
if run_async:
task = self.start_background_task(self.handlers[event],
*args)
Expand Down
4 changes: 2 additions & 2 deletions src/engineio/async_drivers/aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio
import inspect
import sys
from urllib.parse import urlsplit

Expand Down Expand Up @@ -105,7 +105,7 @@ async def send(self, message):
f = self._sock.send_bytes
else:
f = self._sock.send_str
if asyncio.iscoroutinefunction(f):
if inspect.iscoroutinefunction(f):
await f(message)
else:
f(message)
Expand Down
6 changes: 3 additions & 3 deletions src/engineio/async_drivers/asgi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
import asyncio
import inspect

from engineio.static_files import get_static_file

Expand Down Expand Up @@ -102,7 +102,7 @@ async def lifespan(self, scope, receive, send):
if self.on_startup:
try:
await self.on_startup() \
if asyncio.iscoroutinefunction(self.on_startup) \
if inspect.iscoroutinefunction(self.on_startup) \
else self.on_startup()
except:
await send({'type': 'lifespan.startup.failed'})
Expand All @@ -112,7 +112,7 @@ async def lifespan(self, scope, receive, send):
if self.on_shutdown:
try:
await self.on_shutdown() \
if asyncio.iscoroutinefunction(self.on_shutdown) \
if inspect.iscoroutinefunction(self.on_shutdown) \
else self.on_shutdown()
except:
await send({'type': 'lifespan.shutdown.failed'})
Expand Down
7 changes: 4 additions & 3 deletions src/engineio/async_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import urllib

from . import base_server
Expand Down Expand Up @@ -209,7 +210,7 @@ async def handle_request(self, *args, **kwargs):
Note: this method is a coroutine.
"""
translate_request = self._async['translate_request']
if asyncio.iscoroutinefunction(translate_request):
if inspect.iscoroutinefunction(translate_request):
environ = await translate_request(*args, **kwargs)
else:
environ = translate_request(*args, **kwargs)
Expand Down Expand Up @@ -416,7 +417,7 @@ def create_event(self, *args, **kwargs):
async def _make_response(self, response_dict, environ):
cors_headers = self._cors_headers(environ)
make_response = self._async['make_response']
if asyncio.iscoroutinefunction(make_response):
if inspect.iscoroutinefunction(make_response):
response = await make_response(
response_dict['status'],
response_dict['headers'] + cors_headers,
Expand Down Expand Up @@ -488,7 +489,7 @@ async def _trigger_event(self, event, *args, **kwargs):
run_async = kwargs.pop('run_async', False)
ret = None
if event in self.handlers:
if asyncio.iscoroutinefunction(self.handlers[event]):
if inspect.iscoroutinefunction(self.handlers[event]):
async def run_async_handler():
try:
return await self.handlers[event](*args)
Expand Down
Loading