diff --git a/dash/_callback.py b/dash/_callback.py index 141a8a626d..9b272895c8 100644 --- a/dash/_callback.py +++ b/dash/_callback.py @@ -1,11 +1,10 @@ import collections import hashlib +import inspect from functools import wraps from typing import Callable, Optional, Any, List, Tuple, Union, Dict - -import asyncio import flask from .dependencies import ( @@ -49,7 +48,7 @@ async def _async_invoke_callback( func, *args, **kwargs ): # used to mark the frame for the debugger # Check if the function is a coroutine function - if asyncio.iscoroutinefunction(func): + if inspect.iscoroutinefunction(func): return await func(*args, **kwargs) # %% callback invoked %% # If the function is not a coroutine, call it directly return func(*args, **kwargs) # %% callback invoked %% @@ -814,7 +813,7 @@ async def async_add_context(*args, **kwargs): return jsonResponse - if asyncio.iscoroutinefunction(func): + if inspect.iscoroutinefunction(func): callback_map[callback_id]["callback"] = async_add_context else: callback_map[callback_id]["callback"] = add_context diff --git a/dash/_jupyter.py b/dash/_jupyter.py index 5f2606d5c7..85668127df 100644 --- a/dash/_jupyter.py +++ b/dash/_jupyter.py @@ -202,7 +202,7 @@ def capture_event(stream, ident, parent): if _jupyter_comm_response_received(): break - if asyncio.iscoroutinefunction(kernel.do_one_iteration): + if inspect.iscoroutinefunction(kernel.do_one_iteration): loop = asyncio.get_event_loop() nest_asyncio.apply(loop) loop.run_until_complete(kernel.do_one_iteration()) diff --git a/dash/background_callback/managers/celery_manager.py b/dash/background_callback/managers/celery_manager.py index 9a741272b0..d68c65168d 100644 --- a/dash/background_callback/managers/celery_manager.py +++ b/dash/background_callback/managers/celery_manager.py @@ -1,3 +1,4 @@ +import inspect import json import traceback from contextvars import copy_context @@ -250,7 +251,7 @@ async def async_run(): result_key, json.dumps(user_callback_output, cls=PlotlyJSONEncoder) ) - if asyncio.iscoroutinefunction(fn): + if inspect.iscoroutinefunction(fn): func = partial(ctx.run, async_run) asyncio.run(func()) else: diff --git a/dash/background_callback/managers/diskcache_manager.py b/dash/background_callback/managers/diskcache_manager.py index f00886367f..db7cd112bc 100644 --- a/dash/background_callback/managers/diskcache_manager.py +++ b/dash/background_callback/managers/diskcache_manager.py @@ -1,3 +1,4 @@ +import inspect import traceback from contextvars import copy_context import asyncio @@ -296,7 +297,7 @@ async def async_run(): except Exception as err: # pylint: disable=broad-except print(f"Diskcache manager couldn't save output: {err}") - if asyncio.iscoroutinefunction(fn): + if inspect.iscoroutinefunction(fn): func = partial(ctx.run, async_run) asyncio.run(func()) else: diff --git a/dash/dash.py b/dash/dash.py index 546526d1c4..749e38d107 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -2,6 +2,7 @@ import os import sys import collections +import inspect import importlib import warnings from contextvars import copy_context @@ -220,7 +221,7 @@ def _do_skip(error): async def execute_async_function(func, *args, **kwargs): # Check if the function is a coroutine function - if asyncio.iscoroutinefunction(func): + if inspect.iscoroutinefunction(func): return await func(*args, **kwargs) # If the function is not a coroutine, call it directly return func(*args, **kwargs) @@ -837,7 +838,7 @@ async def _parse_body_async(): return _parse_body_async for path, func in self.callback_api_paths.items(): - if asyncio.iscoroutinefunction(func): + if inspect.iscoroutinefunction(func): self._add_url(path, make_parse_body_async(func), ["POST"]) else: self._add_url(path, make_parse_body(func), ["POST"])