diff --git a/src/socketio/async_admin.py b/src/socketio/async_admin.py index b052d8f..b426b71 100644 --- a/src/socketio/async_admin.py +++ b/src/socketio/async_admin.py @@ -1,6 +1,7 @@ import asyncio from datetime import datetime, timezone import functools +import inspect import os import socket import time @@ -124,7 +125,7 @@ class InstrumentedAsyncServer: elif isinstance(self.auth, list): authenticated = client_auth in self.auth else: - if asyncio.iscoroutinefunction(self.auth): + if inspect.iscoroutinefunction(self.auth): authenticated = await self.auth(client_auth) else: authenticated = self.auth(client_auth) diff --git a/src/socketio/async_client.py b/src/socketio/async_client.py index ead963d..49241ed 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -1,4 +1,5 @@ import asyncio +import inspect import logging import random @@ -375,7 +376,7 @@ class AsyncClient(base_client.BaseClient): callables.""" if not callable(value): return value - if asyncio.iscoroutinefunction(value): + if inspect.iscoroutinefunction(value): return await value() return value() @@ -437,7 +438,7 @@ class AsyncClient(base_client.BaseClient): else: del self.callbacks[namespace][id] if callback is not None: - if asyncio.iscoroutinefunction(callback): + if inspect.iscoroutinefunction(callback): await callback(*data) else: callback(*data) @@ -464,7 +465,7 @@ class AsyncClient(base_client.BaseClient): # first see if we have an explicit handler for the event handler, args = self._get_event_handler(event, namespace, args) if handler: - if asyncio.iscoroutinefunction(handler): + if inspect.iscoroutinefunction(handler): try: try: ret = await handler(*args) diff --git a/src/socketio/async_manager.py b/src/socketio/async_manager.py index 47e7a79..19028b0 100644 --- a/src/socketio/async_manager.py +++ b/src/socketio/async_manager.py @@ -1,4 +1,5 @@ import asyncio +import inspect from engineio import packet as eio_packet from socketio import packet @@ -113,7 +114,7 @@ class AsyncManager(BaseManager): del self.callbacks[sid][id] if callback is not None: ret = callback(*data) - if asyncio.iscoroutine(ret): + if inspect.iscoroutine(ret): try: await ret except asyncio.CancelledError: # pragma: no cover diff --git a/src/socketio/async_namespace.py b/src/socketio/async_namespace.py index 42d6508..4035e33 100644 --- a/src/socketio/async_namespace.py +++ b/src/socketio/async_namespace.py @@ -1,4 +1,5 @@ import asyncio +import inspect from socketio import base_namespace @@ -32,7 +33,7 @@ class AsyncNamespace(base_namespace.BaseServerNamespace): handler_name = 'on_' + (event or '') if hasattr(self, handler_name): handler = getattr(self, handler_name) - if asyncio.iscoroutinefunction(handler) is True: + if inspect.iscoroutinefunction(handler) is True: try: try: ret = await handler(*args) @@ -213,7 +214,7 @@ class AsyncClientNamespace(base_namespace.BaseClientNamespace): handler_name = 'on_' + (event or '') if hasattr(self, handler_name): handler = getattr(self, handler_name) - if asyncio.iscoroutinefunction(handler) is True: + if inspect.iscoroutinefunction(handler) is True: try: try: ret = await handler(*args) diff --git a/src/socketio/async_server.py b/src/socketio/async_server.py index 6c9e3ca..e13009e 100644 --- a/src/socketio/async_server.py +++ b/src/socketio/async_server.py @@ -1,4 +1,5 @@ import asyncio +import inspect import engineio @@ -637,7 +638,7 @@ class AsyncServer(base_server.BaseServer): # first see if we have an explicit handler for the event handler, args = self._get_event_handler(event, namespace, args) if handler: - if asyncio.iscoroutinefunction(handler): + if inspect.iscoroutinefunction(handler): try: try: ret = await handler(*args)