File tree 3 files changed +22
-0
lines changed 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 15
15
"event" ,
16
16
)
17
17
18
+ import asyncio
18
19
import functools
19
20
import traceback
20
21
import warnings
@@ -575,6 +576,10 @@ async def _run(self) -> None:
575
576
try :
576
577
with ctx ():
577
578
await self ._fn ()
579
+
580
+ # Yield so that messages can be sent to the client if necessary.
581
+ # https://github.com/posit-dev/py-shiny/issues/1381
582
+ await asyncio .sleep (0 )
578
583
except SilentException :
579
584
# It's OK for SilentException to cause an Effect to stop running
580
585
pass
Original file line number Diff line number Diff line change 4
4
5
5
__all__ = ("Session" , "Inputs" , "Outputs" )
6
6
7
+ import asyncio
7
8
import contextlib
8
9
import dataclasses
9
10
import enum
@@ -653,6 +654,12 @@ def verify_state(expected_state: ConnectionState) -> None:
653
654
f"Unrecognized method { message_obj ['method' ]} "
654
655
)
655
656
657
+ # Progress messages (of the "{binding: {id: xxx}}"" variety) may
658
+ # have queued up at this point; let them drain before we send
659
+ # the next message.
660
+ # https://github.com/posit-dev/py-shiny/issues/1381
661
+ await asyncio .sleep (0 )
662
+
656
663
self ._request_flush ()
657
664
658
665
await flush ()
Original file line number Diff line number Diff line change @@ -67,6 +67,16 @@ async def _sleep(self, delay: float) -> None:
67
67
self ._i += 1
68
68
# Oldest first
69
69
self ._sleepers .sort ()
70
+
71
+ # This is necessary for some tests that call logic that internally awaits on
72
+ # asyncio.sleep(0). Without this, they hang.
73
+ #
74
+ # Another potential workaround would've been to check if delay <= 0 and just
75
+ # return. But this solution has the nice property of actually yielding control
76
+ # (I think...!), which is the whole point of asyncio.sleep(0).
77
+ if not self ._is_advancing :
78
+ await self .advance_time (0 )
79
+
70
80
await wake .wait ()
71
81
72
82
You can’t perform that action at this time.
0 commit comments