bounded_subprocess 2.1.0__tar.gz → 2.3.0__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.

Potentially problematic release.


This version of bounded_subprocess might be problematic. Click here for more details.

Files changed (32) hide show
  1. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/PKG-INFO +1 -1
  2. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/pyproject.toml +1 -1
  3. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/src/bounded_subprocess/bounded_subprocess.py +9 -3
  4. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/src/bounded_subprocess/bounded_subprocess_async.py +9 -4
  5. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/src/bounded_subprocess/util.py +16 -1
  6. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/uv.lock +1 -1
  7. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/.github/workflows/test.yml +0 -0
  8. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/.gitignore +0 -0
  9. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/LICENSE.txt +0 -0
  10. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/Makefile +0 -0
  11. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/README.md +0 -0
  12. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/cspell.config.yaml +0 -0
  13. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/src/bounded_subprocess/__init__.py +0 -0
  14. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/src/bounded_subprocess/interactive.py +0 -0
  15. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/src/bounded_subprocess/interactive_async.py +0 -0
  16. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/__init__.py +0 -0
  17. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/block_on_inputs.py +0 -0
  18. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/close_outputs.py +0 -0
  19. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/dies_shortly_after_launch.py +0 -0
  20. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/dies_while_writing.py +0 -0
  21. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/does_not_read.py +0 -0
  22. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/echo_stdin.py +0 -0
  23. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/fork_bomb.py +0 -0
  24. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/fork_once.py +0 -0
  25. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/long_stdout.py +0 -0
  26. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/sleep_forever.py +0 -0
  27. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/unbounded_output.py +0 -0
  28. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/evil_programs/write_forever_but_no_newline.py +0 -0
  29. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/module_test.py +0 -0
  30. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/test_async.py +0 -0
  31. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/test_interactive.py +0 -0
  32. {bounded_subprocess-2.1.0 → bounded_subprocess-2.3.0}/test/test_interactive_async.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bounded_subprocess
3
- Version: 2.1.0
3
+ Version: 2.3.0
4
4
  Summary: A library to facilitate running subprocesses that may misbehave.
5
5
  Project-URL: Homepage, https://github.com/arjunguha/bounded_subprocess
6
6
  Project-URL: Bug Tracker, https://github.com/arjunguha/bounded_subprocess
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "bounded_subprocess"
3
- version = "2.1.0"
3
+ version = "2.3.0"
4
4
  authors = [
5
5
  { name="Arjun Guha" },
6
6
  { name="Ming-Ho Yee" },
@@ -7,6 +7,7 @@ from .util import (
7
7
  SLEEP_BETWEEN_READS,
8
8
  write_loop_sync,
9
9
  _STDIN_WRITE_TIMEOUT,
10
+ SLEEP_BETWEEN_WRITES,
10
11
  )
11
12
 
12
13
 
@@ -16,6 +17,7 @@ def run(
16
17
  max_output_size: int = 2048,
17
18
  env=None,
18
19
  stdin_data: Optional[str] = None,
20
+ stdin_write_timeout: Optional[int] = None,
19
21
  ) -> Result:
20
22
  """
21
23
  Runs the given program with arguments. After the timeout elapses, kills the process
@@ -24,12 +26,16 @@ def run(
24
26
  """
25
27
  state = BoundedSubprocessState(args, env, max_output_size, stdin_data is not None)
26
28
  if stdin_data is not None:
27
- write_loop_sync(
29
+ ok = write_loop_sync(
28
30
  state.write_chunk,
29
31
  stdin_data.encode(),
30
- _STDIN_WRITE_TIMEOUT,
31
- sleep_interval=SLEEP_BETWEEN_READS,
32
+ stdin_write_timeout if stdin_write_timeout is not None else 15,
33
+ sleep_interval=SLEEP_BETWEEN_WRITES,
32
34
  )
35
+ if not ok:
36
+ state.terminate()
37
+ return Result(True, -1, "", "failed to write to stdin")
38
+
33
39
  state.close_stdin()
34
40
 
35
41
  # We sleep for 0.1 seconds in each iteration.
@@ -6,6 +6,7 @@ from .util import (
6
6
  SLEEP_BETWEEN_READS,
7
7
  write_loop_async,
8
8
  _STDIN_WRITE_TIMEOUT,
9
+ SLEEP_BETWEEN_WRITES,
9
10
  )
10
11
 
11
12
 
@@ -15,6 +16,7 @@ async def run(
15
16
  max_output_size: int = 2048,
16
17
  env=None,
17
18
  stdin_data: Optional[str] = None,
19
+ stdin_write_timeout: Optional[int] = None,
18
20
  ) -> Result:
19
21
  """
20
22
  Runs the given program with arguments. After the timeout elapses, kills the process
@@ -27,13 +29,16 @@ async def run(
27
29
  # async here? It's just the sleep between reads.
28
30
  state = BoundedSubprocessState(args, env, max_output_size, stdin_data is not None)
29
31
  if stdin_data is not None:
30
- await write_loop_async(
32
+ ok = await write_loop_async(
31
33
  state.write_chunk,
32
34
  stdin_data.encode(),
33
- _STDIN_WRITE_TIMEOUT,
34
- sleep_interval=SLEEP_BETWEEN_READS,
35
+ stdin_write_timeout if stdin_write_timeout is not None else 15,
36
+ sleep_interval=SLEEP_BETWEEN_WRITES,
35
37
  )
36
- state.close_stdin()
38
+ if not ok:
39
+ state.terminate()
40
+ return Result(True, -1, "", "failed to write to stdin")
41
+ await state.close_stdin_async(_STDIN_WRITE_TIMEOUT)
37
42
 
38
43
  # We sleep for 0.1 seconds in each iteration.
39
44
  max_iterations = timeout_seconds * 10
@@ -9,7 +9,8 @@ import asyncio
9
9
 
10
10
  MAX_BYTES_PER_READ = 1024
11
11
  SLEEP_BETWEEN_READS = 0.1
12
- _STDIN_WRITE_TIMEOUT = 1.0
12
+ _STDIN_WRITE_TIMEOUT = 15
13
+ SLEEP_BETWEEN_WRITES = 0.01
13
14
 
14
15
 
15
16
  class Result:
@@ -147,6 +148,20 @@ class BoundedSubprocessState:
147
148
  except BrokenPipeError:
148
149
  pass
149
150
 
151
+ async def close_stdin_async(self, timeout: int) -> None:
152
+ if self.p.stdin is None:
153
+ return
154
+ for _ in range(timeout):
155
+ try:
156
+ self.p.stdin.close()
157
+ return
158
+ except BlockingIOError:
159
+ await asyncio.sleep(1)
160
+ except BrokenPipeError:
161
+ return
162
+
163
+
164
+
150
165
  def try_read(self) -> bool:
151
166
  """
152
167
  Reads from the process. Returning False indicates that we should stop
@@ -4,7 +4,7 @@ requires-python = ">=3.9"
4
4
 
5
5
  [[package]]
6
6
  name = "bounded-subprocess"
7
- version = "1.5.0"
7
+ version = "2.2.0"
8
8
  source = { editable = "." }
9
9
  dependencies = [
10
10
  { name = "typeguard" },