Skip to content

Commit 2d9a930

Browse files
committed
Adjustments for use_async and determining whether the app can be use as async. Added more defined error messages when libraries are missing or async was used without async turned on.
1 parent 0dd778e commit 2d9a930

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

dash/dash.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,25 @@ def __init__( # pylint: disable=too-many-statements
443443
routing_callback_inputs: Optional[Dict[str, Union[Input, State]]] = None,
444444
description: Optional[str] = None,
445445
on_error: Optional[Callable[[Exception], Any]] = None,
446-
use_async: Optional[bool] = False,
446+
use_async: Optional[bool] = None,
447447
**obsolete,
448448
):
449+
450+
if use_async is None:
451+
try:
452+
import asgiref
453+
454+
use_async = True
455+
except ImportError:
456+
pass
457+
elif use_async:
458+
try:
459+
import asgiref
460+
except ImportError:
461+
raise Exception(
462+
"You are trying to use dash[async] without having installed the requirements please install via: `pip install dash[async]`"
463+
)
464+
449465
_validate.check_obsolete(obsolete)
450466

451467
caller_name = None if name else get_caller_name()
@@ -1539,6 +1555,11 @@ def dispatch(self):
15391555

15401556
response_data = ctx.run(partial_func)
15411557

1558+
if asyncio.iscoroutine(response_data):
1559+
raise Exception(
1560+
"You are trying to use a coroutine without dash[async], please install the dependencies via `pip install dash[async]` and make sure you arent passing `use_async=False` to the app."
1561+
)
1562+
15421563
response.set_data(response_data)
15431564
return response
15441565

0 commit comments

Comments
 (0)