shellsim 0.1.14__tar.gz → 0.1.15__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 (183) hide show
  1. {shellsim-0.1.14 → shellsim-0.1.15}/Cargo.lock +1 -1
  2. {shellsim-0.1.14 → shellsim-0.1.15}/Cargo.toml +1 -1
  3. {shellsim-0.1.14 → shellsim-0.1.15}/PKG-INFO +1 -1
  4. {shellsim-0.1.14 → shellsim-0.1.15}/python/native/Cargo.lock +2 -2
  5. {shellsim-0.1.14 → shellsim-0.1.15}/python/native/Cargo.toml +1 -1
  6. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/asyncio.py +82 -13
  7. {shellsim-0.1.14 → shellsim-0.1.15}/LICENSE +0 -0
  8. {shellsim-0.1.14 → shellsim-0.1.15}/README.md +0 -0
  9. {shellsim-0.1.14 → shellsim-0.1.15}/pyproject.toml +0 -0
  10. {shellsim-0.1.14 → shellsim-0.1.15}/python/native/src/lib.rs +0 -0
  11. {shellsim-0.1.14 → shellsim-0.1.15}/python/shellsim/__init__.py +0 -0
  12. {shellsim-0.1.14 → shellsim-0.1.15}/python/shellsim/__main__.py +0 -0
  13. {shellsim-0.1.14 → shellsim-0.1.15}/python/shellsim/_api.py +0 -0
  14. {shellsim-0.1.14 → shellsim-0.1.15}/python/shellsim/_cli.py +0 -0
  15. {shellsim-0.1.14 → shellsim-0.1.15}/python/shellsim/py.typed +0 -0
  16. {shellsim-0.1.14 → shellsim-0.1.15}/python/shellsim/python.py +0 -0
  17. {shellsim-0.1.14 → shellsim-0.1.15}/rust-toolchain.toml +0 -0
  18. {shellsim-0.1.14 → shellsim-0.1.15}/src/bin/shellsim-python.rs +0 -0
  19. {shellsim-0.1.14 → shellsim-0.1.15}/src/clock.rs +0 -0
  20. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/archives.rs +0 -0
  21. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/awk/ast.rs +0 -0
  22. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/awk/eval.rs +0 -0
  23. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/awk/lexer.rs +0 -0
  24. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/awk/parser.rs +0 -0
  25. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/awk.rs +0 -0
  26. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/builtins.rs +0 -0
  27. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/dd.rs +0 -0
  28. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/echo.rs +0 -0
  29. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/find.rs +0 -0
  30. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/fs.rs +0 -0
  31. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/apply.rs +0 -0
  32. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/commit.rs +0 -0
  33. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/compare.rs +0 -0
  34. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/config.rs +0 -0
  35. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/conflict.rs +0 -0
  36. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/diff.rs +0 -0
  37. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/ignore.rs +0 -0
  38. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/import.rs +0 -0
  39. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/log.rs +0 -0
  40. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/merge.rs +0 -0
  41. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/mod.rs +0 -0
  42. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/plumbing.rs +0 -0
  43. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/rebase.rs +0 -0
  44. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/refs.rs +0 -0
  45. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/repo.rs +0 -0
  46. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/stash.rs +0 -0
  47. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/switch.rs +0 -0
  48. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/git/worktree.rs +0 -0
  49. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/hashing.rs +0 -0
  50. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/makecmd.rs +0 -0
  51. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/mod.rs +0 -0
  52. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/net.rs +0 -0
  53. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/options.rs +0 -0
  54. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/patch.rs +0 -0
  55. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/pkg.rs +0 -0
  56. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/printf.rs +0 -0
  57. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/proc.rs +0 -0
  58. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/regex_compat.rs +0 -0
  59. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/rgcmd.rs +0 -0
  60. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/sed.rs +0 -0
  61. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/sort.rs +0 -0
  62. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/system.rs +0 -0
  63. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/tarcmd.rs +0 -0
  64. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/text.rs +0 -0
  65. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/unavailable.rs +0 -0
  66. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/util.rs +0 -0
  67. {shellsim-0.1.14 → shellsim-0.1.15}/src/commands/zipcmd.rs +0 -0
  68. {shellsim-0.1.14 → shellsim-0.1.15}/src/descriptors.rs +0 -0
  69. {shellsim-0.1.14 → shellsim-0.1.15}/src/exec.rs +0 -0
  70. {shellsim-0.1.14 → shellsim-0.1.15}/src/expand.rs +0 -0
  71. {shellsim-0.1.14 → shellsim-0.1.15}/src/harness.rs +0 -0
  72. {shellsim-0.1.14 → shellsim-0.1.15}/src/harness_manager.rs +0 -0
  73. {shellsim-0.1.14 → shellsim-0.1.15}/src/hashes.rs +0 -0
  74. {shellsim-0.1.14 → shellsim-0.1.15}/src/host_ingest.rs +0 -0
  75. {shellsim-0.1.14 → shellsim-0.1.15}/src/interp.rs +0 -0
  76. {shellsim-0.1.14 → shellsim-0.1.15}/src/jqcmd.rs +0 -0
  77. {shellsim-0.1.14 → shellsim-0.1.15}/src/lib.rs +0 -0
  78. {shellsim-0.1.14 → shellsim-0.1.15}/src/main.rs +0 -0
  79. {shellsim-0.1.14 → shellsim-0.1.15}/src/mcp.rs +0 -0
  80. {shellsim-0.1.14 → shellsim-0.1.15}/src/net.rs +0 -0
  81. {shellsim-0.1.14 → shellsim-0.1.15}/src/netcmd.rs +0 -0
  82. {shellsim-0.1.14 → shellsim-0.1.15}/src/process.rs +0 -0
  83. {shellsim-0.1.14 → shellsim-0.1.15}/src/pseudo_fs.rs +0 -0
  84. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/ast.rs +0 -0
  85. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/bytecode.rs +0 -0
  86. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/compiler.rs +0 -0
  87. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/filesystem.rs +0 -0
  88. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/heap.rs +0 -0
  89. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/http.rs +0 -0
  90. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/lexer.rs +0 -0
  91. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/mapping.rs +0 -0
  92. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/mod.rs +0 -0
  93. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/native.rs +0 -0
  94. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/number.rs +0 -0
  95. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/object_model.rs +0 -0
  96. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/parser.rs +0 -0
  97. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/process.rs +0 -0
  98. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/protocol.rs +0 -0
  99. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/slice.rs +0 -0
  100. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/source.rs +0 -0
  101. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/argparse.rs +0 -0
  102. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/asyncio.rs +0 -0
  103. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/base64.rs +0 -0
  104. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/bisect.rs +0 -0
  105. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/collections.rs +0 -0
  106. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/core.rs +0 -0
  107. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/dataclasses.rs +0 -0
  108. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/enum.rs +0 -0
  109. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/frozen.rs +0 -0
  110. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/functools.rs +0 -0
  111. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/hashlib.rs +0 -0
  112. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/heapq.rs +0 -0
  113. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/http.rs +0 -0
  114. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/importlib.rs +0 -0
  115. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/itertools.rs +0 -0
  116. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/json.rs +0 -0
  117. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/math.rs +0 -0
  118. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/mod.rs +0 -0
  119. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/numpy.rs +0 -0
  120. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/os.rs +0 -0
  121. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/pytest.rs +0 -0
  122. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/re.rs +0 -0
  123. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/abc.py +0 -0
  124. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/base64.py +0 -0
  125. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/cmath.py +0 -0
  126. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/codecs.py +0 -0
  127. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/collections.py +0 -0
  128. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/complex.py +0 -0
  129. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/copy.py +0 -0
  130. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/csv.py +0 -0
  131. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/datetime.py +0 -0
  132. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/glob.py +0 -0
  133. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/hashlib.py +0 -0
  134. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/http.py +0 -0
  135. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/http_client.py +0 -0
  136. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/importlib.py +0 -0
  137. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/io.py +0 -0
  138. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/json.py +0 -0
  139. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/logging.py +0 -0
  140. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/numpy_random.py +0 -0
  141. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/os.py +0 -0
  142. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/pathlib.py +0 -0
  143. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/pytest.py +0 -0
  144. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/random.py +0 -0
  145. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/shutil.py +0 -0
  146. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/statistics.py +0 -0
  147. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/struct.py +0 -0
  148. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/subprocess.py +0 -0
  149. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/tempfile.py +0 -0
  150. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/textwrap.py +0 -0
  151. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/urllib.py +0 -0
  152. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/urllib_error.py +0 -0
  153. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/urllib_request.py +0 -0
  154. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/uuid.py +0 -0
  155. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/zipfile.py +0 -0
  156. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/source/zlib.py +0 -0
  157. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/string.rs +0 -0
  158. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/struct.rs +0 -0
  159. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/subprocess.rs +0 -0
  160. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/sys.rs +0 -0
  161. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/time.rs +0 -0
  162. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/typing.rs +0 -0
  163. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/unittest.rs +0 -0
  164. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/vfs.rs +0 -0
  165. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/stdlib/zlib.rs +0 -0
  166. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/string.rs +0 -0
  167. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/token.rs +0 -0
  168. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm/calls.rs +0 -0
  169. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm/dispatch.rs +0 -0
  170. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm/host.rs +0 -0
  171. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm/iteration.rs +0 -0
  172. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm/namespace.rs +0 -0
  173. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm/native_runtime.rs +0 -0
  174. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm/objects.rs +0 -0
  175. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm/operations.rs +0 -0
  176. {shellsim-0.1.14 → shellsim-0.1.15}/src/python/vm.rs +0 -0
  177. {shellsim-0.1.14 → shellsim-0.1.15}/src/resources.rs +0 -0
  178. {shellsim-0.1.14 → shellsim-0.1.15}/src/sandbox.rs +0 -0
  179. {shellsim-0.1.14 → shellsim-0.1.15}/src/scenario.rs +0 -0
  180. {shellsim-0.1.14 → shellsim-0.1.15}/src/scheduler.rs +0 -0
  181. {shellsim-0.1.14 → shellsim-0.1.15}/src/shell.rs +0 -0
  182. {shellsim-0.1.14 → shellsim-0.1.15}/src/telemetry.rs +0 -0
  183. {shellsim-0.1.14 → shellsim-0.1.15}/src/vfs.rs +0 -0
@@ -330,7 +330,7 @@ dependencies = [
330
330
 
331
331
  [[package]]
332
332
  name = "shellsim"
333
- version = "0.1.14"
333
+ version = "0.1.15"
334
334
  dependencies = [
335
335
  "base64",
336
336
  "crc32fast",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "shellsim"
3
- version = "0.1.14"
3
+ version = "0.1.15"
4
4
  edition = "2021"
5
5
  description = "In-process BusyBox-like environment for RL rollouts and agent tests"
6
6
  license = "Apache-2.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shellsim
3
- Version: 0.1.14
3
+ Version: 0.1.15
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: License :: OSI Approved :: Apache Software License
6
6
  Classifier: Operating System :: MacOS :: MacOS X
@@ -406,7 +406,7 @@ dependencies = [
406
406
 
407
407
  [[package]]
408
408
  name = "shellsim"
409
- version = "0.1.14"
409
+ version = "0.1.15"
410
410
  dependencies = [
411
411
  "base64",
412
412
  "crc32fast",
@@ -427,7 +427,7 @@ dependencies = [
427
427
 
428
428
  [[package]]
429
429
  name = "shellsim-python-bindings"
430
- version = "0.1.14"
430
+ version = "0.1.15"
431
431
  dependencies = [
432
432
  "pyo3",
433
433
  "serde",
@@ -2,7 +2,7 @@
2
2
 
3
3
  [package]
4
4
  name = "shellsim-python-bindings"
5
- version = "0.1.14"
5
+ version = "0.1.15"
6
6
  edition = "2021"
7
7
  description = "Python bindings for shellsim"
8
8
  license = "Apache-2.0"
@@ -197,6 +197,24 @@ class Future:
197
197
  self._loop._wake_waiters(self)
198
198
 
199
199
 
200
+ class _GatheringFuture(Future):
201
+ def __init__(self, children, *, loop):
202
+ Future.__init__(self, loop=loop)
203
+ self._children = children
204
+ self._cancel_requested = False
205
+
206
+ def cancel(self, msg=None):
207
+ if self._done:
208
+ return False
209
+ cancelled = False
210
+ for child in self._children:
211
+ if child.cancel(msg=msg):
212
+ cancelled = True
213
+ if cancelled:
214
+ self._cancel_requested = True
215
+ return cancelled
216
+
217
+
200
218
  class Task:
201
219
  def __init__(self, coroutine, loop, name=None):
202
220
  if not _is_coroutine(coroutine):
@@ -737,7 +755,10 @@ class _Loop:
737
755
  self._ready.append(task)
738
756
 
739
757
  def _cancel(self, task):
740
- if isinstance(task._waiting_on, Future) and task._waiting_on.cancel():
758
+ dependency = task._waiting_on
759
+ if isinstance(dependency, (Task, Future)) and dependency.cancel():
760
+ return
761
+ if isinstance(dependency, _TimeoutWait) and dependency.child.cancel():
741
762
  return
742
763
  if not task._started:
743
764
  task._done = True
@@ -856,8 +877,7 @@ class _Loop:
856
877
  else:
857
878
  self._schedule(task, awaited._result)
858
879
  else:
859
- if isinstance(awaited, Future):
860
- task._waiting_on = awaited
880
+ task._waiting_on = awaited
861
881
  awaited._waiters.append(task)
862
882
 
863
883
  def _dispatch_yield(self, task, awaited):
@@ -978,17 +998,50 @@ async def sleep(delay, result=None):
978
998
  return result
979
999
 
980
1000
 
981
- async def gather(*coroutines, return_exceptions=False):
1001
+ def gather(*coroutines, return_exceptions=False):
982
1002
  tasks = [_ensure_task(coroutine) for coroutine in coroutines]
983
- results = []
1003
+ observed = []
984
1004
  for task in tasks:
985
- try:
986
- results.append(await task)
987
- except Exception as error:
1005
+ if task not in observed:
1006
+ observed.append(task)
1007
+ loop = get_running_loop()
1008
+ outer = _GatheringFuture(observed, loop=loop)
1009
+ if not tasks:
1010
+ outer.set_result([])
1011
+ return outer
1012
+
1013
+ results = [None for task in tasks]
1014
+ completed = [False for task in tasks]
1015
+
1016
+ def child_completed(child):
1017
+ if outer.done():
1018
+ return
1019
+ if outer._cancel_requested:
1020
+ if all(task.done() for task in observed):
1021
+ outer.set_exception(CancelledError())
1022
+ return
1023
+ if child.cancelled():
1024
+ if not return_exceptions:
1025
+ outer.set_exception(CancelledError())
1026
+ return
1027
+ result = CancelledError()
1028
+ elif child.exception() is not None:
988
1029
  if not return_exceptions:
989
- raise
990
- results.append(error)
991
- return results
1030
+ outer.set_exception(child.exception())
1031
+ return
1032
+ result = child.exception()
1033
+ else:
1034
+ result = child.result()
1035
+ for index in range(len(tasks)):
1036
+ if tasks[index] is child:
1037
+ completed[index] = True
1038
+ results[index] = result
1039
+ if all(completed):
1040
+ outer.set_result(results)
1041
+
1042
+ for task in observed:
1043
+ task.add_done_callback(child_completed)
1044
+ return outer
992
1045
 
993
1046
 
994
1047
  async def wait_for(awaitable, timeout):
@@ -1147,8 +1200,24 @@ def as_completed(awaitables, timeout=None):
1147
1200
  yield next_result()
1148
1201
 
1149
1202
 
1150
- async def shield(awaitable):
1151
- return await _ensure_task(awaitable)
1203
+ def shield(awaitable):
1204
+ inner = _ensure_task(awaitable)
1205
+ if inner.done():
1206
+ return inner
1207
+ outer = get_running_loop().create_future()
1208
+
1209
+ def inner_completed(completed):
1210
+ if outer.done():
1211
+ return
1212
+ if completed.cancelled():
1213
+ outer.cancel()
1214
+ elif completed.exception() is not None:
1215
+ outer.set_exception(completed.exception())
1216
+ else:
1217
+ outer.set_result(completed.result())
1218
+
1219
+ inner.add_done_callback(inner_completed)
1220
+ return outer
1152
1221
 
1153
1222
 
1154
1223
  async def create_subprocess_exec(program, *args, stdin=None, stdout=None, stderr=None,
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
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