shellsim 0.1.12__tar.gz → 0.1.13__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.12 → shellsim-0.1.13}/Cargo.lock +1 -1
  2. {shellsim-0.1.12 → shellsim-0.1.13}/Cargo.toml +1 -1
  3. {shellsim-0.1.12 → shellsim-0.1.13}/PKG-INFO +1 -1
  4. {shellsim-0.1.12 → shellsim-0.1.13}/python/native/Cargo.lock +2 -2
  5. {shellsim-0.1.12 → shellsim-0.1.13}/python/native/Cargo.toml +1 -1
  6. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/asyncio.py +182 -11
  7. {shellsim-0.1.12 → shellsim-0.1.13}/LICENSE +0 -0
  8. {shellsim-0.1.12 → shellsim-0.1.13}/README.md +0 -0
  9. {shellsim-0.1.12 → shellsim-0.1.13}/pyproject.toml +0 -0
  10. {shellsim-0.1.12 → shellsim-0.1.13}/python/native/src/lib.rs +0 -0
  11. {shellsim-0.1.12 → shellsim-0.1.13}/python/shellsim/__init__.py +0 -0
  12. {shellsim-0.1.12 → shellsim-0.1.13}/python/shellsim/__main__.py +0 -0
  13. {shellsim-0.1.12 → shellsim-0.1.13}/python/shellsim/_api.py +0 -0
  14. {shellsim-0.1.12 → shellsim-0.1.13}/python/shellsim/_cli.py +0 -0
  15. {shellsim-0.1.12 → shellsim-0.1.13}/python/shellsim/py.typed +0 -0
  16. {shellsim-0.1.12 → shellsim-0.1.13}/python/shellsim/python.py +0 -0
  17. {shellsim-0.1.12 → shellsim-0.1.13}/rust-toolchain.toml +0 -0
  18. {shellsim-0.1.12 → shellsim-0.1.13}/src/bin/shellsim-python.rs +0 -0
  19. {shellsim-0.1.12 → shellsim-0.1.13}/src/clock.rs +0 -0
  20. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/archives.rs +0 -0
  21. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/awk/ast.rs +0 -0
  22. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/awk/eval.rs +0 -0
  23. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/awk/lexer.rs +0 -0
  24. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/awk/parser.rs +0 -0
  25. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/awk.rs +0 -0
  26. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/builtins.rs +0 -0
  27. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/dd.rs +0 -0
  28. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/echo.rs +0 -0
  29. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/find.rs +0 -0
  30. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/fs.rs +0 -0
  31. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/apply.rs +0 -0
  32. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/commit.rs +0 -0
  33. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/compare.rs +0 -0
  34. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/config.rs +0 -0
  35. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/conflict.rs +0 -0
  36. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/diff.rs +0 -0
  37. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/ignore.rs +0 -0
  38. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/import.rs +0 -0
  39. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/log.rs +0 -0
  40. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/merge.rs +0 -0
  41. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/mod.rs +0 -0
  42. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/plumbing.rs +0 -0
  43. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/rebase.rs +0 -0
  44. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/refs.rs +0 -0
  45. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/repo.rs +0 -0
  46. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/stash.rs +0 -0
  47. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/switch.rs +0 -0
  48. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/git/worktree.rs +0 -0
  49. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/hashing.rs +0 -0
  50. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/makecmd.rs +0 -0
  51. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/mod.rs +0 -0
  52. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/net.rs +0 -0
  53. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/options.rs +0 -0
  54. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/patch.rs +0 -0
  55. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/pkg.rs +0 -0
  56. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/printf.rs +0 -0
  57. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/proc.rs +0 -0
  58. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/regex_compat.rs +0 -0
  59. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/rgcmd.rs +0 -0
  60. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/sed.rs +0 -0
  61. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/sort.rs +0 -0
  62. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/system.rs +0 -0
  63. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/tarcmd.rs +0 -0
  64. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/text.rs +0 -0
  65. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/unavailable.rs +0 -0
  66. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/util.rs +0 -0
  67. {shellsim-0.1.12 → shellsim-0.1.13}/src/commands/zipcmd.rs +0 -0
  68. {shellsim-0.1.12 → shellsim-0.1.13}/src/descriptors.rs +0 -0
  69. {shellsim-0.1.12 → shellsim-0.1.13}/src/exec.rs +0 -0
  70. {shellsim-0.1.12 → shellsim-0.1.13}/src/expand.rs +0 -0
  71. {shellsim-0.1.12 → shellsim-0.1.13}/src/harness.rs +0 -0
  72. {shellsim-0.1.12 → shellsim-0.1.13}/src/harness_manager.rs +0 -0
  73. {shellsim-0.1.12 → shellsim-0.1.13}/src/hashes.rs +0 -0
  74. {shellsim-0.1.12 → shellsim-0.1.13}/src/host_ingest.rs +0 -0
  75. {shellsim-0.1.12 → shellsim-0.1.13}/src/interp.rs +0 -0
  76. {shellsim-0.1.12 → shellsim-0.1.13}/src/jqcmd.rs +0 -0
  77. {shellsim-0.1.12 → shellsim-0.1.13}/src/lib.rs +0 -0
  78. {shellsim-0.1.12 → shellsim-0.1.13}/src/main.rs +0 -0
  79. {shellsim-0.1.12 → shellsim-0.1.13}/src/mcp.rs +0 -0
  80. {shellsim-0.1.12 → shellsim-0.1.13}/src/net.rs +0 -0
  81. {shellsim-0.1.12 → shellsim-0.1.13}/src/netcmd.rs +0 -0
  82. {shellsim-0.1.12 → shellsim-0.1.13}/src/process.rs +0 -0
  83. {shellsim-0.1.12 → shellsim-0.1.13}/src/pseudo_fs.rs +0 -0
  84. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/ast.rs +0 -0
  85. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/bytecode.rs +0 -0
  86. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/compiler.rs +0 -0
  87. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/filesystem.rs +0 -0
  88. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/heap.rs +0 -0
  89. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/http.rs +0 -0
  90. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/lexer.rs +0 -0
  91. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/mapping.rs +0 -0
  92. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/mod.rs +0 -0
  93. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/native.rs +0 -0
  94. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/number.rs +0 -0
  95. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/object_model.rs +0 -0
  96. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/parser.rs +0 -0
  97. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/process.rs +0 -0
  98. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/protocol.rs +0 -0
  99. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/slice.rs +0 -0
  100. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/source.rs +0 -0
  101. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/argparse.rs +0 -0
  102. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/asyncio.rs +0 -0
  103. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/base64.rs +0 -0
  104. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/bisect.rs +0 -0
  105. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/collections.rs +0 -0
  106. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/core.rs +0 -0
  107. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/dataclasses.rs +0 -0
  108. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/enum.rs +0 -0
  109. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/frozen.rs +0 -0
  110. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/functools.rs +0 -0
  111. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/hashlib.rs +0 -0
  112. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/heapq.rs +0 -0
  113. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/http.rs +0 -0
  114. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/importlib.rs +0 -0
  115. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/itertools.rs +0 -0
  116. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/json.rs +0 -0
  117. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/math.rs +0 -0
  118. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/mod.rs +0 -0
  119. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/numpy.rs +0 -0
  120. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/os.rs +0 -0
  121. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/pytest.rs +0 -0
  122. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/re.rs +0 -0
  123. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/abc.py +0 -0
  124. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/base64.py +0 -0
  125. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/cmath.py +0 -0
  126. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/codecs.py +0 -0
  127. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/collections.py +0 -0
  128. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/complex.py +0 -0
  129. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/copy.py +0 -0
  130. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/csv.py +0 -0
  131. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/datetime.py +0 -0
  132. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/glob.py +0 -0
  133. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/hashlib.py +0 -0
  134. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/http.py +0 -0
  135. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/http_client.py +0 -0
  136. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/importlib.py +0 -0
  137. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/io.py +0 -0
  138. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/json.py +0 -0
  139. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/logging.py +0 -0
  140. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/numpy_random.py +0 -0
  141. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/os.py +0 -0
  142. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/pathlib.py +0 -0
  143. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/pytest.py +0 -0
  144. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/random.py +0 -0
  145. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/shutil.py +0 -0
  146. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/statistics.py +0 -0
  147. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/struct.py +0 -0
  148. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/subprocess.py +0 -0
  149. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/tempfile.py +0 -0
  150. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/textwrap.py +0 -0
  151. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/urllib.py +0 -0
  152. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/urllib_error.py +0 -0
  153. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/urllib_request.py +0 -0
  154. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/uuid.py +0 -0
  155. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/zipfile.py +0 -0
  156. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/source/zlib.py +0 -0
  157. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/string.rs +0 -0
  158. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/struct.rs +0 -0
  159. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/subprocess.rs +0 -0
  160. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/sys.rs +0 -0
  161. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/time.rs +0 -0
  162. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/typing.rs +0 -0
  163. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/unittest.rs +0 -0
  164. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/vfs.rs +0 -0
  165. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/stdlib/zlib.rs +0 -0
  166. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/string.rs +0 -0
  167. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/token.rs +0 -0
  168. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm/calls.rs +0 -0
  169. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm/dispatch.rs +0 -0
  170. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm/host.rs +0 -0
  171. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm/iteration.rs +0 -0
  172. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm/namespace.rs +0 -0
  173. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm/native_runtime.rs +0 -0
  174. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm/objects.rs +0 -0
  175. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm/operations.rs +0 -0
  176. {shellsim-0.1.12 → shellsim-0.1.13}/src/python/vm.rs +0 -0
  177. {shellsim-0.1.12 → shellsim-0.1.13}/src/resources.rs +0 -0
  178. {shellsim-0.1.12 → shellsim-0.1.13}/src/sandbox.rs +0 -0
  179. {shellsim-0.1.12 → shellsim-0.1.13}/src/scenario.rs +0 -0
  180. {shellsim-0.1.12 → shellsim-0.1.13}/src/scheduler.rs +0 -0
  181. {shellsim-0.1.12 → shellsim-0.1.13}/src/shell.rs +0 -0
  182. {shellsim-0.1.12 → shellsim-0.1.13}/src/telemetry.rs +0 -0
  183. {shellsim-0.1.12 → shellsim-0.1.13}/src/vfs.rs +0 -0
@@ -330,7 +330,7 @@ dependencies = [
330
330
 
331
331
  [[package]]
332
332
  name = "shellsim"
333
- version = "0.1.12"
333
+ version = "0.1.13"
334
334
  dependencies = [
335
335
  "base64",
336
336
  "crc32fast",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "shellsim"
3
- version = "0.1.12"
3
+ version = "0.1.13"
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.12
3
+ Version: 0.1.13
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.12"
409
+ version = "0.1.13"
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.12"
430
+ version = "0.1.13"
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.12"
5
+ version = "0.1.13"
6
6
  edition = "2021"
7
7
  description = "Python bindings for shellsim"
8
8
  license = "Apache-2.0"
@@ -25,6 +25,14 @@ class CancelledError(Exception):
25
25
  pass
26
26
 
27
27
 
28
+ class QueueEmpty(Exception):
29
+ pass
30
+
31
+
32
+ class QueueFull(Exception):
33
+ pass
34
+
35
+
28
36
  class _Sleep:
29
37
  def __init__(self, delay):
30
38
  self.delay = delay
@@ -40,6 +48,12 @@ class _QueueGet:
40
48
  self.queue = queue
41
49
 
42
50
 
51
+ class _QueuePut:
52
+ def __init__(self, queue, item):
53
+ self.queue = queue
54
+ self.item = item
55
+
56
+
43
57
  class _LockWait:
44
58
  def __init__(self, lock):
45
59
  self.lock = lock
@@ -90,6 +104,7 @@ class Task:
90
104
  self._name = name
91
105
  self._callbacks = []
92
106
  self._cancel_requests = 0
107
+ self._logical_task = self
93
108
 
94
109
  def done(self):
95
110
  return self._done
@@ -176,33 +191,108 @@ class Queue:
176
191
  self._maxsize = maxsize
177
192
  self._items = []
178
193
  self._getters = []
194
+ self._putters = []
195
+ self._unfinished_tasks = 0
196
+ self._finished = Event()
197
+ self._finished.set()
198
+
199
+ @property
200
+ def maxsize(self):
201
+ return self._maxsize
179
202
 
180
203
  def empty(self):
181
204
  return len(self._items) == 0
182
205
 
206
+ def full(self):
207
+ return self._maxsize > 0 and len(self._items) >= self._maxsize
208
+
183
209
  def qsize(self):
184
210
  return len(self._items)
185
211
 
186
- def put_nowait(self, item):
187
- if self._getters:
212
+ def _put(self, item):
213
+ self._items.append(item)
214
+
215
+ def _get(self):
216
+ return self._items.pop(0)
217
+
218
+ def _next_getter(self):
219
+ while self._getters:
188
220
  task = self._getters.pop(0)
189
- task._loop._schedule(task, item)
221
+ if not task.done():
222
+ return task
223
+ return None
224
+
225
+ def _next_putter(self):
226
+ while self._putters:
227
+ task, item = self._putters.pop(0)
228
+ if not task.done():
229
+ return task, item
230
+ return None
231
+
232
+ def _put_item(self, item):
233
+ self._unfinished_tasks += 1
234
+ self._finished.clear()
235
+ getter = self._next_getter()
236
+ if getter is None:
237
+ self._put(item)
190
238
  else:
191
- self._items.append(item)
239
+ getter._loop._schedule(getter, item)
240
+
241
+ def _wake_putter(self):
242
+ putter = self._next_putter()
243
+ if putter is None:
244
+ return
245
+ task, item = putter
246
+ self._put_item(item)
247
+ task._loop._schedule(task, None)
248
+
249
+ def _get_item(self):
250
+ item = self._get()
251
+ self._wake_putter()
252
+ return item
253
+
254
+ def put_nowait(self, item):
255
+ if self.full():
256
+ raise QueueFull()
257
+ self._put_item(item)
192
258
 
193
259
  async def put(self, item):
194
- self.put_nowait(item)
260
+ if self.full():
261
+ return await _QueuePut(self, item)
262
+ self._put_item(item)
195
263
 
196
264
  def get_nowait(self):
197
265
  if not self._items:
198
- raise RuntimeError("queue is empty")
199
- return self._items.pop(0)
266
+ raise QueueEmpty()
267
+ return self._get_item()
200
268
 
201
269
  async def get(self):
202
270
  if self._items:
203
- return self._items.pop(0)
271
+ return self._get_item()
204
272
  return await _QueueGet(self)
205
273
 
274
+ def task_done(self):
275
+ if self._unfinished_tasks <= 0:
276
+ raise ValueError("task_done() called too many times")
277
+ self._unfinished_tasks -= 1
278
+ if self._unfinished_tasks == 0:
279
+ self._finished.set()
280
+
281
+ async def join(self):
282
+ if self._unfinished_tasks:
283
+ await self._finished.wait()
284
+
285
+
286
+ class PriorityQueue(Queue):
287
+ def _put(self, item):
288
+ self._items.append(item)
289
+ self._items.sort()
290
+
291
+
292
+ class LifoQueue(Queue):
293
+ def _get(self):
294
+ return self._items.pop()
295
+
206
296
 
207
297
  class Lock:
208
298
  def __init__(self):
@@ -493,6 +583,14 @@ class _Loop:
493
583
  self._ready.append(task)
494
584
  return task
495
585
 
586
+ def _create_awaited_task(self, coroutine, parent):
587
+ task = self.create_task(coroutine)
588
+ task._logical_task = parent._logical_task
589
+ return task
590
+
591
+ def time(self):
592
+ return _monotonic_ns() / 1000000000
593
+
496
594
  def _schedule(self, task, value):
497
595
  if not task._done:
498
596
  self._resource_waiters = [
@@ -623,9 +721,15 @@ class _Loop:
623
721
  awaited.event._waiters.append(task)
624
722
  elif isinstance(awaited, _QueueGet):
625
723
  if awaited.queue._items:
626
- self._schedule(task, awaited.queue._items.pop(0))
724
+ self._schedule(task, awaited.queue._get_item())
627
725
  else:
628
726
  awaited.queue._getters.append(task)
727
+ elif isinstance(awaited, _QueuePut):
728
+ if awaited.queue.full():
729
+ awaited.queue._putters.append((task, awaited.item))
730
+ else:
731
+ awaited.queue._put_item(awaited.item)
732
+ self._schedule(task, None)
629
733
  elif isinstance(awaited, _LockWait):
630
734
  awaited.lock._waiters.append(task)
631
735
  elif isinstance(awaited, _SemaphoreWait):
@@ -645,7 +749,7 @@ class _Loop:
645
749
  elif isinstance(awaited, _ResourceWait):
646
750
  self._resource_waiters.append((task, awaited.token))
647
751
  elif _is_coroutine(awaited):
648
- self._block_on_task(task, self.create_task(awaited))
752
+ self._block_on_task(task, self._create_awaited_task(awaited, task))
649
753
  else:
650
754
  raise TypeError("object cannot be used in 'await' expression")
651
755
 
@@ -690,7 +794,9 @@ def ensure_future(awaitable):
690
794
  def current_task(loop=None):
691
795
  if loop is None:
692
796
  loop = get_running_loop()
693
- return loop._current
797
+ if loop._current is None:
798
+ return None
799
+ return loop._current._logical_task
694
800
 
695
801
 
696
802
  def all_tasks(loop=None):
@@ -730,6 +836,71 @@ async def wait_for(awaitable, timeout):
730
836
  return await _WaitFor(task, timeout)
731
837
 
732
838
 
839
+ class Timeout:
840
+ def __init__(self, when):
841
+ self._when = when
842
+ self._task = None
843
+ self._timer = None
844
+ self._cancelling = 0
845
+ self._expired = False
846
+
847
+ def when(self):
848
+ return self._when
849
+
850
+ def expired(self):
851
+ return self._expired
852
+
853
+ def reschedule(self, when):
854
+ if self._task is None:
855
+ raise RuntimeError("Timeout has not been entered")
856
+ if self._expired:
857
+ raise RuntimeError("Cannot change state of expired Timeout")
858
+ if self._timer is not None:
859
+ self._timer.cancel()
860
+ self._when = when
861
+ self._timer = self._start_timer()
862
+
863
+ def _start_timer(self):
864
+ if self._when is None:
865
+ return None
866
+
867
+ async def expire():
868
+ delay = self._when - get_running_loop().time()
869
+ await sleep(delay)
870
+ self._expired = True
871
+ self._task.cancel()
872
+
873
+ return create_task(expire())
874
+
875
+ async def __aenter__(self):
876
+ if self._task is not None:
877
+ raise RuntimeError("Timeout has already been entered")
878
+ self._task = current_task()
879
+ self._cancelling = self._task.cancelling()
880
+ self._timer = self._start_timer()
881
+ return self
882
+
883
+ async def __aexit__(self, kind, value, traceback):
884
+ if self._timer is not None:
885
+ self._timer.cancel()
886
+ if not self._expired:
887
+ return False
888
+ remaining = self._task.uncancel()
889
+ if remaining <= self._cancelling and isinstance(value, CancelledError):
890
+ raise TimeoutError()
891
+ return False
892
+
893
+
894
+ def timeout(delay):
895
+ if delay is None:
896
+ return Timeout(None)
897
+ return Timeout(get_running_loop().time() + delay)
898
+
899
+
900
+ def timeout_at(when):
901
+ return Timeout(when)
902
+
903
+
733
904
  def _wait_condition(tasks, return_when):
734
905
  done = {task for task in tasks if task.done()}
735
906
  if return_when == FIRST_COMPLETED:
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