bounded_subprocess 2.1.0__py3-none-any.whl → 2.3.0__py3-none-any.whl
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.
- bounded_subprocess/bounded_subprocess.py +9 -3
- bounded_subprocess/bounded_subprocess_async.py +9 -4
- bounded_subprocess/util.py +16 -1
- {bounded_subprocess-2.1.0.dist-info → bounded_subprocess-2.3.0.dist-info}/METADATA +1 -1
- bounded_subprocess-2.3.0.dist-info/RECORD +10 -0
- bounded_subprocess-2.1.0.dist-info/RECORD +0 -10
- {bounded_subprocess-2.1.0.dist-info → bounded_subprocess-2.3.0.dist-info}/WHEEL +0 -0
- {bounded_subprocess-2.1.0.dist-info → bounded_subprocess-2.3.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -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
|
-
|
|
31
|
-
sleep_interval=
|
|
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
|
-
|
|
34
|
-
sleep_interval=
|
|
35
|
+
stdin_write_timeout if stdin_write_timeout is not None else 15,
|
|
36
|
+
sleep_interval=SLEEP_BETWEEN_WRITES,
|
|
35
37
|
)
|
|
36
|
-
|
|
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
|
bounded_subprocess/util.py
CHANGED
|
@@ -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 =
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bounded_subprocess
|
|
3
|
-
Version: 2.
|
|
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
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
bounded_subprocess/__init__.py,sha256=L88cc8vG7GE11T0fF1-tMUIbRRlOmmlCqa6wopP3Ox8,1003
|
|
2
|
+
bounded_subprocess/bounded_subprocess.py,sha256=BkGDiPKuyl3Mftn6kUkdUbIfeXuLCYWDo57T1uAa-hI,1470
|
|
3
|
+
bounded_subprocess/bounded_subprocess_async.py,sha256=hN323BOureEZFpT26-FmfK4K2WXZnP2VAc8mDqxOEeQ,1813
|
|
4
|
+
bounded_subprocess/interactive.py,sha256=4fG4NB3eN5rqssUpfjiEQL2F-S7eDBwB2Mw1gzCL3Qk,4149
|
|
5
|
+
bounded_subprocess/interactive_async.py,sha256=WKPA2XBnq_qMh5WijyoSOpg2iJcsYcQSXNGjv6IEEfA,1979
|
|
6
|
+
bounded_subprocess/util.py,sha256=kYrq1Bcuvczx4oSxzVfztMDDHbsMUr68FyN6Bh-zhaU,6789
|
|
7
|
+
bounded_subprocess-2.3.0.dist-info/METADATA,sha256=Sk2zX0VawscdNUHuFtbXCOqrc8qx0WxxcCj_UAt4nD4,2664
|
|
8
|
+
bounded_subprocess-2.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
bounded_subprocess-2.3.0.dist-info/licenses/LICENSE.txt,sha256=UVerBV0_1vMFt8QkaXuVnZVSlOiKDiBSieK5MNLy4Ls,1086
|
|
10
|
+
bounded_subprocess-2.3.0.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
bounded_subprocess/__init__.py,sha256=L88cc8vG7GE11T0fF1-tMUIbRRlOmmlCqa6wopP3Ox8,1003
|
|
2
|
-
bounded_subprocess/bounded_subprocess.py,sha256=-UuVhlbuMEWDNDjr_9tSUkcRxb-3RZKqOqup0nQI0zA,1231
|
|
3
|
-
bounded_subprocess/bounded_subprocess_async.py,sha256=XSvi-FiKZbVbREnKDGiSG4UVViVoUBCCQzEohAS5GwM,1543
|
|
4
|
-
bounded_subprocess/interactive.py,sha256=4fG4NB3eN5rqssUpfjiEQL2F-S7eDBwB2Mw1gzCL3Qk,4149
|
|
5
|
-
bounded_subprocess/interactive_async.py,sha256=WKPA2XBnq_qMh5WijyoSOpg2iJcsYcQSXNGjv6IEEfA,1979
|
|
6
|
-
bounded_subprocess/util.py,sha256=zaTl2LkhyOelRGotlgISkKy8cURQaTTNweTYoSchISA,6402
|
|
7
|
-
bounded_subprocess-2.1.0.dist-info/METADATA,sha256=sxiscwiihS4QqFDVzXhgnwDfPdFBWunmX7N8KScypCw,2664
|
|
8
|
-
bounded_subprocess-2.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
-
bounded_subprocess-2.1.0.dist-info/licenses/LICENSE.txt,sha256=UVerBV0_1vMFt8QkaXuVnZVSlOiKDiBSieK5MNLy4Ls,1086
|
|
10
|
-
bounded_subprocess-2.1.0.dist-info/RECORD,,
|
|
File without changes
|
{bounded_subprocess-2.1.0.dist-info → bounded_subprocess-2.3.0.dist-info}/licenses/LICENSE.txt
RENAMED
|
File without changes
|