param 2.4.2rc1__tar.gz → 2.4.2rc2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. {param-2.4.2rc1 → param-2.4.2rc2}/PKG-INFO +1 -1
  2. {param-2.4.2rc1 → param-2.4.2rc2}/param/_utils.py +55 -4
  3. {param-2.4.2rc1 → param-2.4.2rc2}/param/_version.py +2 -2
  4. {param-2.4.2rc1 → param-2.4.2rc2}/param/reactive.py +30 -8
  5. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testreactive.py +201 -0
  6. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testutils.py +51 -0
  7. {param-2.4.2rc1 → param-2.4.2rc2}/.gitignore +0 -0
  8. {param-2.4.2rc1 → param-2.4.2rc2}/LICENSE.txt +0 -0
  9. {param-2.4.2rc1 → param-2.4.2rc2}/README.md +0 -0
  10. {param-2.4.2rc1 → param-2.4.2rc2}/numbergen/__init__.py +0 -0
  11. {param-2.4.2rc1 → param-2.4.2rc2}/param/__init__.py +0 -0
  12. {param-2.4.2rc1 → param-2.4.2rc2}/param/depends.py +0 -0
  13. {param-2.4.2rc1 → param-2.4.2rc2}/param/display.py +0 -0
  14. {param-2.4.2rc1 → param-2.4.2rc2}/param/ipython.py +0 -0
  15. {param-2.4.2rc1 → param-2.4.2rc2}/param/mypy_plugin.py +0 -0
  16. {param-2.4.2rc1 → param-2.4.2rc2}/param/parameterized.py +0 -0
  17. {param-2.4.2rc1 → param-2.4.2rc2}/param/parameters.py +0 -0
  18. {param-2.4.2rc1 → param-2.4.2rc2}/param/py.typed +0 -0
  19. {param-2.4.2rc1 → param-2.4.2rc2}/param/serializer.py +0 -0
  20. {param-2.4.2rc1 → param-2.4.2rc2}/param/version.py +0 -0
  21. {param-2.4.2rc1 → param-2.4.2rc2}/pyproject.toml +0 -0
  22. {param-2.4.2rc1 → param-2.4.2rc2}/tests/__init__.py +0 -0
  23. {param-2.4.2rc1 → param-2.4.2rc2}/tests/assert_types.py +0 -0
  24. {param-2.4.2rc1 → param-2.4.2rc2}/tests/conftest.py +0 -0
  25. {param-2.4.2rc1 → param-2.4.2rc2}/tests/pyrightconfig-bare.json +0 -0
  26. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testaddparameter.py +0 -0
  27. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testbind.py +0 -0
  28. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testbooleanparam.py +0 -0
  29. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testbytesparam.py +0 -0
  30. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testcalendardateparam.py +0 -0
  31. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testcalendardaterangeparam.py +0 -0
  32. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testcallable.py +0 -0
  33. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testclassselector.py +0 -0
  34. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testcolorparameter.py +0 -0
  35. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testcomparator.py +0 -0
  36. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testcompositeparams.py +0 -0
  37. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testcustomparam.py +0 -0
  38. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testdateparam.py +0 -0
  39. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testdaterangeparam.py +0 -0
  40. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testdefaultfactory.py +0 -0
  41. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testdefaults.py +0 -0
  42. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testdeprecations.py +0 -0
  43. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testdynamicparams.py +0 -0
  44. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testfiledeserialization.py +0 -0
  45. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testfileselector.py +0 -0
  46. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testimports.py +0 -0
  47. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testipythonmagic.py +0 -0
  48. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testjsonserialization.py +0 -0
  49. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testlist.py +0 -0
  50. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testlistselector.py +0 -0
  51. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testmultifileselector.py +0 -0
  52. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testnumbergen.py +0 -0
  53. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testnumberparameter.py +0 -0
  54. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testnumpy.py +0 -0
  55. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testobjectselector.py +0 -0
  56. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testpandas.py +0 -0
  57. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testparamdepends.py +0 -0
  58. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testparameter.py +0 -0
  59. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testparameterizedobject.py +0 -0
  60. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testparameterizedrepr.py +0 -0
  61. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testparamoutput.py +0 -0
  62. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testparamunion.py +0 -0
  63. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testpathparam.py +0 -0
  64. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testpickle.py +0 -0
  65. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testrangeparameter.py +0 -0
  66. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testrefs.py +0 -0
  67. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testreprhtml.py +0 -0
  68. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testselector.py +0 -0
  69. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testsignatures.py +0 -0
  70. {param-2.4.2rc1 → param-2.4.2rc2}/tests/teststringparam.py +0 -0
  71. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testtimedependent.py +0 -0
  72. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testtupleparam.py +0 -0
  73. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testversion.py +0 -0
  74. {param-2.4.2rc1 → param-2.4.2rc2}/tests/testwatch.py +0 -0
  75. {param-2.4.2rc1 → param-2.4.2rc2}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: param
3
- Version: 2.4.2rc1
3
+ Version: 2.4.2rc2
4
4
  Summary: Declarative parameters for robust Python classes and a rich API for reactive programming
5
5
  Project-URL: Homepage, https://param.holoviz.org/
6
6
  Project-URL: Tracker, https://github.com/holoviz/param/issues
@@ -12,7 +12,7 @@ import warnings
12
12
  from collections import OrderedDict, abc, defaultdict
13
13
  from contextlib import contextmanager
14
14
  from textwrap import dedent
15
- from threading import get_ident
15
+ from threading import get_ident, local
16
16
 
17
17
  if t.TYPE_CHECKING:
18
18
  import asyncio
@@ -608,18 +608,69 @@ def _in_ipython():
608
608
 
609
609
  _running_tasks: set[asyncio.Task] = set()
610
610
 
611
+ _thread_state = local()
612
+
613
+ def _fallback_event_loop() -> asyncio.AbstractEventLoop:
614
+ """
615
+ Return the event loop to drive coroutines on when nothing else is running.
616
+
617
+ The loop is cached per thread and reused, since creating one per call leaks
618
+ the file descriptors each loop holds. It is kept thread-local because
619
+ ``run_until_complete`` may not be driven from two threads at once.
620
+ """
621
+ import asyncio
622
+ event_loop = getattr(_thread_state, 'event_loop', None)
623
+ if event_loop is None or event_loop.is_closed():
624
+ event_loop = asyncio.new_event_loop()
625
+ _thread_state.event_loop = event_loop
626
+ return event_loop
627
+
628
+ def _drain_fallback_loop(event_loop: asyncio.AbstractEventLoop) -> None:
629
+ """
630
+ Finish off anything left running on the fallback loop.
631
+
632
+ A coroutine driven by :func:`async_executor` may schedule further work
633
+ before it completes, which ``run_until_complete`` leaves pending. Since the
634
+ loop is reused, such a leftover would otherwise resume in the middle of an
635
+ unrelated drive, so it is cancelled and given the chance to clean up here.
636
+ """
637
+ import asyncio
638
+ pending = [task for task in asyncio.all_tasks(event_loop) if not task.done()]
639
+ if not pending:
640
+ return
641
+ for task in pending:
642
+ task.cancel()
643
+ event_loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
644
+
611
645
  def async_executor(func):
646
+ """
647
+ Schedule the awaitable returned by ``func`` on the running event loop.
648
+
649
+ Without a running loop the awaitable is instead driven to completion on a
650
+ loop of param's own, i.e. the call blocks the caller until the coroutine
651
+ has finished. Applications that can offer a loop (such as Panel) are
652
+ expected to override ``param.parameterized.async_executor``.
653
+ """
612
654
  import asyncio
613
655
  try:
614
656
  event_loop = asyncio.get_running_loop()
615
657
  except RuntimeError:
616
- event_loop = asyncio.new_event_loop()
617
- if event_loop.is_running():
658
+ event_loop = None
659
+ if event_loop is not None:
618
660
  task = asyncio.ensure_future(func())
619
661
  _running_tasks.add(task)
620
662
  task.add_done_callback(_running_tasks.discard)
621
- else:
663
+ return
664
+ event_loop = _fallback_event_loop()
665
+ try:
622
666
  event_loop.run_until_complete(func())
667
+ except asyncio.CancelledError:
668
+ # A coroutine superseded while it was being driven synchronously must
669
+ # not surface the cancellation in the caller, which is generally an
670
+ # unrelated attribute access or parameter update.
671
+ pass
672
+ finally:
673
+ _drain_fallback_loop(event_loop)
623
674
 
624
675
  @t.runtime_checkable
625
676
  class _HasTypes(t.Protocol):
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '2.4.2rc1'
22
- __version_tuple__ = version_tuple = (2, 4, 2, 'rc1')
21
+ __version__ = version = '2.4.2rc2'
22
+ __version_tuple__ = version_tuple = (2, 4, 2, 'rc2')
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -1615,7 +1615,8 @@ class rx:
1615
1615
  self._trigger: Trigger | None
1616
1616
  if operation and (iscoroutinefunction(operation['fn']) or inspect.isgeneratorfunction(operation['fn'])):
1617
1617
  self._trigger = Trigger(internal=True)
1618
- self._current_ = Undefined
1618
+ self._current_ = Undefined
1619
+ self._dirty = True # Otherwise current will be stuck as Undefined.
1619
1620
  else:
1620
1621
  self._trigger = None
1621
1622
  self._root = self._compute_root()
@@ -1840,11 +1841,11 @@ class rx:
1840
1841
  # it from the next _lazy_resolve.
1841
1842
  await _close_stale(obj)
1842
1843
  return
1843
- self._current_task = task = asyncio.current_task()
1844
1844
  trigger = self._trigger
1845
+ if trigger is None:
1846
+ return
1847
+ self._current_task = task = asyncio.current_task()
1845
1848
  try:
1846
- if trigger is None:
1847
- return
1848
1849
  if obj is None:
1849
1850
  shared = self._shared
1850
1851
  if shared is None:
@@ -1873,6 +1874,17 @@ class rx:
1873
1874
  trigger.param.trigger('value')
1874
1875
  except asyncio.CancelledError:
1875
1876
  return
1877
+ except Exception as e:
1878
+ if stale():
1879
+ return
1880
+ self._finished_generation = generation
1881
+ if self._dirty or self._root._dirty_obj:
1882
+ # Ignoring as the inputs were invalidated while the async operation was running
1883
+ return
1884
+ # Mirror the synchronous path in _resolve.
1885
+ # For an async generator an raised exception ends the stream.
1886
+ self._error_state = e
1887
+ trigger.param.trigger('value')
1876
1888
  finally:
1877
1889
  if self._current_task is task:
1878
1890
  self._current_task = None
@@ -1907,15 +1919,25 @@ class rx:
1907
1919
  # If this rx is cloned from an shared input then we make use
1908
1920
  # of the shared.rx.value to ensure branching pipelines do
1909
1921
  # not have to recompute the inputs multiple times.
1910
- if self._is_async:
1911
- self._shared.rx.value # trigger async resolve
1922
+ shared = self._shared
1923
+ value = shared.rx.value # triggers async resolve
1924
+ if self._is_async and (
1925
+ shared._awaiting or shared._current_task is not None
1926
+ ):
1927
+ # The shared node is still processing, resolve when finished
1912
1928
  self._lazy_resolve()
1913
1929
  raise Skip
1914
1930
  # Returns instead of raising Skip because this path does
1915
1931
  # resolve to a value, so it must mirror the shared node's
1916
1932
  # skip state rather than be marked skipped by the handler.
1917
- self._current_ = self._shared.rx.value
1918
- self._skipped = self._shared._skipped
1933
+ self._current_ = value
1934
+ self._skipped = shared._skipped
1935
+ if self._is_async:
1936
+ # The value was adopted without scheduling a task, so
1937
+ # claim a generation for it. This supersedes a task an
1938
+ # earlier operation may have scheduled and still awaits a resolution.
1939
+ self._resolve_generation += 1
1940
+ self._finished_generation = self._resolve_generation
1919
1941
  self._dirty = False
1920
1942
  return self._current_
1921
1943
  operation = self._operation
@@ -1069,6 +1069,207 @@ async def test_async_shared_rx_superseded_updates_computed_once(lazy):
1069
1069
  # the superseded updates are not computed at all.
1070
1070
  assert call_count == 2
1071
1071
 
1072
+ async def test_reactive_async_error_raised_on_read():
1073
+ async def mul(value):
1074
+ await asyncio.sleep(0.01)
1075
+ if value == 2:
1076
+ raise RuntimeError('boom')
1077
+ return 10 * value
1078
+
1079
+ irx = rx(1)
1080
+ async_rx = irx.rx.pipe(mul)
1081
+ async_rx.rx.value
1082
+ await async_wait_until(lambda: async_rx.rx.value == 10)
1083
+
1084
+ irx.rx.value = 2
1085
+ async_rx.rx.value
1086
+
1087
+ # The failed operation must settle the node and store the error, so it is
1088
+ # re-raised on every read instead of leaving the node awaiting forever.
1089
+ await async_wait_until(lambda: async_rx._error_state is not None)
1090
+ assert not async_rx._awaiting
1091
+ with pytest.raises(RuntimeError, match='boom'):
1092
+ async_rx.rx.value
1093
+
1094
+ # A new input clears the error and the pipeline recovers.
1095
+ irx.rx.value = 3
1096
+ async_rx.rx.value
1097
+ await async_wait_until(lambda: async_rx.rx.value == 30)
1098
+
1099
+ async def test_reactive_async_error_propagates_downstream():
1100
+ async def mul(value):
1101
+ await asyncio.sleep(0.01)
1102
+ raise RuntimeError('boom')
1103
+
1104
+ irx = rx(1)
1105
+ downstream = irx.rx.pipe(mul) + 10
1106
+ downstream.rx.value
1107
+ await async_wait_until(lambda: downstream._prev._error_state is not None)
1108
+ with pytest.raises(RuntimeError, match='boom'):
1109
+ downstream.rx.value
1110
+
1111
+ async def test_reactive_async_error_propagates_to_shared_branches():
1112
+ async def compute(value):
1113
+ await asyncio.sleep(0.01)
1114
+ raise RuntimeError('boom')
1115
+
1116
+ shared = rx(1).rx.pipe(compute)
1117
+ x_rx = shared.rx.pipe(lambda d: d['x'])
1118
+ y_rx = shared.rx.pipe(lambda d: d['y'])
1119
+
1120
+ x_rx.rx.value
1121
+ y_rx.rx.value
1122
+ await async_wait_until(lambda: not shared._awaiting)
1123
+ for branch in (x_rx, y_rx):
1124
+ with pytest.raises(RuntimeError, match='boom'):
1125
+ branch.rx.value
1126
+
1127
+ async def test_reactive_async_gen_error_ends_stream():
1128
+ async def gen(value):
1129
+ for i in range(3):
1130
+ await asyncio.sleep(0.01)
1131
+ if i == 2:
1132
+ raise RuntimeError('boom')
1133
+ yield value+i
1134
+
1135
+ async_rx = rx(1).rx.pipe(gen)
1136
+ async_rx.rx.value
1137
+ await async_wait_until(lambda: async_rx._error_state is not None)
1138
+
1139
+ # The raise ends the generator's stream and is reported on the next read.
1140
+ assert not async_rx._awaiting
1141
+ with pytest.raises(RuntimeError, match='boom'):
1142
+ async_rx.rx.value
1143
+
1144
+ async def test_reactive_gen_error_ends_stream():
1145
+ def gen(value):
1146
+ yield value
1147
+ raise RuntimeError('boom')
1148
+
1149
+ async_rx = rx(1).rx.pipe(gen)
1150
+ async_rx.rx.value
1151
+ await async_wait_until(lambda: async_rx._error_state is not None)
1152
+ assert not async_rx._awaiting
1153
+ with pytest.raises(RuntimeError, match='boom'):
1154
+ async_rx.rx.value
1155
+
1156
+ async def test_reactive_async_superseded_error_not_recorded():
1157
+ async def mul(value):
1158
+ await asyncio.sleep(0.02)
1159
+ if value == 2:
1160
+ raise RuntimeError('boom')
1161
+ return value*2
1162
+
1163
+ irx = rx(1)
1164
+ async_rx = irx.rx.pipe(mul)
1165
+ async_rx.rx.value
1166
+ await async_wait_until(lambda: async_rx.rx.value == 2)
1167
+
1168
+ irx.rx.value = 2
1169
+ async_rx.rx.value
1170
+ # Yield to the event loop so the failing task is suspended on its await and
1171
+ # is superseded while in flight.
1172
+ await asyncio.sleep(0.01)
1173
+ irx.rx.value = 3
1174
+ async_rx.rx.value
1175
+
1176
+ # The error belongs to a superseded input, so it must not poison the node.
1177
+ await async_wait_until(lambda: async_rx.rx.value == 6)
1178
+ assert async_rx._error_state is None
1179
+ async def _pair(value):
1180
+ await asyncio.sleep(0.02)
1181
+ return (value * 2, value * 3)
1182
+
1183
+ async def test_async_shared_rx_branch_after_settling_resolves():
1184
+ irx = rx(1)
1185
+ node = irx.rx.pipe(_pair)
1186
+ node.rx.value
1187
+ await async_wait_until(lambda: node.rx.value == (2, 3))
1188
+
1189
+ # The branch mirrors a node that has already settled, so it must resolve
1190
+ # on its first read rather than being stranded on Undefined.
1191
+ first = node[0]
1192
+ assert first.rx.value == 2
1193
+
1194
+ irx.rx.value = 3
1195
+ await async_wait_until(lambda: first.rx.value == 6)
1196
+
1197
+ async def test_async_shared_rx_branch_while_awaiting_resolves():
1198
+ irx = rx(1)
1199
+ node = irx.rx.pipe(_pair)
1200
+ node.rx.value
1201
+
1202
+ first = node[0]
1203
+ assert first.rx.value is param.Undefined
1204
+ await async_wait_until(lambda: first.rx.value == 2)
1205
+
1206
+ async def test_async_shared_rx_branch_before_resolving_resolves():
1207
+ irx = rx(1)
1208
+ node = irx.rx.pipe(_pair)
1209
+ first, second = node[0], node[1]
1210
+
1211
+ assert first.rx.value is param.Undefined
1212
+ await async_wait_until(lambda: first.rx.value == 2)
1213
+
1214
+ # The shared node has settled by now, so the sibling branch resolves on
1215
+ # its first read.
1216
+ assert second.rx.value == 3
1217
+
1218
+ async def test_async_shared_rx_branch_computed_once():
1219
+ call_count = 0
1220
+
1221
+ async def count_pair(value):
1222
+ nonlocal call_count
1223
+ call_count += 1
1224
+ await asyncio.sleep(0.02)
1225
+ return (value * 2, value * 3)
1226
+
1227
+ irx = rx(1)
1228
+ node = irx.rx.pipe(count_pair)
1229
+ first, second = node[0], node[1]
1230
+
1231
+ # Request the value for both nodes
1232
+ first.rx.value
1233
+ second.rx.value
1234
+ await async_wait_until(lambda: first.rx.value == 2 and second.rx.value == 3)
1235
+
1236
+ # The branches resolve through the shared node rather than recomputing.
1237
+ assert call_count == 1
1238
+
1239
+ irx.rx.value = 3
1240
+ await async_wait_until(lambda: first.rx.value == 6 and second.rx.value == 9)
1241
+ assert call_count == 2
1242
+
1243
+ async def test_async_shared_rx_branch_notifies_watcher():
1244
+ irx = rx(1)
1245
+ node = irx.rx.pipe(_pair)
1246
+ node.rx.value
1247
+ await async_wait_until(lambda: node.rx.value == (2, 3))
1248
+
1249
+ items = []
1250
+ first = node[0]
1251
+ assert first.rx.value == 2
1252
+ first.rx.watch(items.append)
1253
+
1254
+ irx.rx.value = 3
1255
+ await async_wait_until(lambda: items == [6])
1256
+ assert items == [6]
1257
+
1258
+ async def test_async_gen_shared_rx_branch_resolves():
1259
+ async def gen(value):
1260
+ for i in range(3):
1261
+ await asyncio.sleep(0.02)
1262
+ yield (value + i, i)
1263
+
1264
+ irx = rx(1)
1265
+ node = irx.rx.pipe(gen)
1266
+ node.rx.value
1267
+ await async_wait_until(lambda: node.rx.value == (3, 2))
1268
+
1269
+ # A branch of a generator node adopts the value the generator settled on.
1270
+ first = node[0]
1271
+ assert first.rx.value == 3
1272
+
1072
1273
  @pytest.mark.parametrize('lazy', [False, True])
1073
1274
  def test_root_invalidation(lazy):
1074
1275
  arx = rx('a', lazy=lazy)
@@ -1,3 +1,4 @@
1
+ import asyncio
1
2
  import datetime as dt
2
3
  import os
3
4
 
@@ -16,6 +17,7 @@ from param._utils import (
16
17
  _abbreviate_paths,
17
18
  _is_abstract,
18
19
  _is_mutable_container,
20
+ async_executor,
19
21
  concrete_descendents,
20
22
  descendents,
21
23
  iscoroutinefunction,
@@ -574,3 +576,52 @@ def test_abbreviate_paths():
574
576
  # cd = concrete_descendents(X)
575
577
  # # y not returned
576
578
  # assert cd == {'X': X, 'Y': Y}
579
+
580
+
581
+ def test_async_executor_reuses_fallback_loop():
582
+ loops = []
583
+
584
+ async def record():
585
+ loops.append(asyncio.get_running_loop())
586
+
587
+ async_executor(record)
588
+ async_executor(record)
589
+
590
+ assert len(loops) == 2
591
+ assert loops[0] is loops[1]
592
+ assert not loops[0].is_closed()
593
+
594
+
595
+ def test_async_executor_ignores_cancellation():
596
+ async def cancel_self():
597
+ asyncio.current_task().cancel()
598
+ await asyncio.sleep(0)
599
+
600
+ # A cancellation must not surface in the caller, which is generally an
601
+ # unrelated attribute access or parameter update.
602
+ async_executor(cancel_self)
603
+
604
+
605
+ def test_async_executor_does_not_resume_leftover_tasks():
606
+ progress = []
607
+
608
+ async def leftover():
609
+ progress.append('started')
610
+ await asyncio.sleep(10)
611
+ progress.append('finished')
612
+
613
+ async def schedule():
614
+ # There is a running loop at this point, so this is scheduled rather
615
+ # than driven to completion.
616
+ async_executor(leftover)
617
+ await asyncio.sleep(0)
618
+
619
+ async def noop():
620
+ await asyncio.sleep(0)
621
+
622
+ async_executor(schedule)
623
+ assert progress == ['started']
624
+
625
+ # The abandoned task must not resume in the middle of a later drive.
626
+ async_executor(noop)
627
+ assert progress == ['started']
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes