bounded_subprocess 1.5.0__py3-none-any.whl → 2.0.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/__init__.py +30 -26
- bounded_subprocess/bounded_subprocess.py +30 -0
- {bounded_subprocess-1.5.0.dist-info → bounded_subprocess-2.0.0.dist-info}/METADATA +1 -1
- bounded_subprocess-2.0.0.dist-info/RECORD +10 -0
- bounded_subprocess-1.5.0.dist-info/RECORD +0 -9
- {bounded_subprocess-1.5.0.dist-info → bounded_subprocess-2.0.0.dist-info}/WHEEL +0 -0
- {bounded_subprocess-1.5.0.dist-info → bounded_subprocess-2.0.0.dist-info}/licenses/LICENSE.txt +0 -0
bounded_subprocess/__init__.py
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"""
|
|
2
|
+
Bounded subprocess execution with timeout and output limits.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
This package provides convenient functions for running subprocesses with bounded
|
|
5
|
+
execution time and output size, with support for both synchronous and asynchronous
|
|
6
|
+
execution patterns.
|
|
7
|
+
"""
|
|
5
8
|
|
|
9
|
+
__version__ = "1.0.0"
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
# Lazy imports for better startup performance
|
|
12
|
+
def __getattr__(name):
|
|
13
|
+
if name == "run":
|
|
14
|
+
from .bounded_subprocess import run
|
|
15
|
+
return run
|
|
16
|
+
elif name == "Result":
|
|
17
|
+
from .util import Result
|
|
18
|
+
return Result
|
|
19
|
+
elif name == "BoundedSubprocessState":
|
|
20
|
+
from .util import BoundedSubprocessState
|
|
21
|
+
return BoundedSubprocessState
|
|
22
|
+
elif name == "SLEEP_BETWEEN_READS":
|
|
23
|
+
from .util import SLEEP_BETWEEN_READS
|
|
24
|
+
return SLEEP_BETWEEN_READS
|
|
25
|
+
else:
|
|
26
|
+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
else:
|
|
28
|
-
break
|
|
29
|
-
|
|
30
|
-
return state.terminate()
|
|
28
|
+
# Expose key classes and constants for convenience
|
|
29
|
+
__all__ = [
|
|
30
|
+
"run",
|
|
31
|
+
"Result",
|
|
32
|
+
"BoundedSubprocessState",
|
|
33
|
+
"SLEEP_BETWEEN_READS"
|
|
34
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from .util import Result, BoundedSubprocessState, SLEEP_BETWEEN_READS
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def run(
|
|
8
|
+
args: List[str],
|
|
9
|
+
timeout_seconds: int = 15,
|
|
10
|
+
max_output_size: int = 2048,
|
|
11
|
+
env=None,
|
|
12
|
+
) -> Result:
|
|
13
|
+
"""
|
|
14
|
+
Runs the given program with arguments. After the timeout elapses, kills the process
|
|
15
|
+
and all other processes in the process group. Captures at most max_output_size bytes
|
|
16
|
+
of stdout and stderr each, and discards any output beyond that.
|
|
17
|
+
"""
|
|
18
|
+
state = BoundedSubprocessState(args, env, max_output_size)
|
|
19
|
+
|
|
20
|
+
# We sleep for 0.1 seconds in each iteration.
|
|
21
|
+
max_iterations = timeout_seconds * 10
|
|
22
|
+
|
|
23
|
+
for _ in range(max_iterations):
|
|
24
|
+
keep_reading = state.try_read()
|
|
25
|
+
if keep_reading:
|
|
26
|
+
time.sleep(SLEEP_BETWEEN_READS)
|
|
27
|
+
else:
|
|
28
|
+
break
|
|
29
|
+
|
|
30
|
+
return state.terminate()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bounded_subprocess
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.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=_lfjoVwzhlHfrysg20ESinumiThnaZaOorIbjRTySpY,854
|
|
3
|
+
bounded_subprocess/bounded_subprocess_async.py,sha256=uvwMhB0OSJ91qJXVFlIzWfNQXQzw9I8WV7RdNzNWVDc,1158
|
|
4
|
+
bounded_subprocess/interactive.py,sha256=Vn-002fH6rAekOwugGqdZUZ3O3x1wY-mLxApBtyC-DA,5016
|
|
5
|
+
bounded_subprocess/interactive_async.py,sha256=igxFfeC7zdQxX34-pQRlTNgYIpSbVFgmGYCCvpwsMPw,5085
|
|
6
|
+
bounded_subprocess/util.py,sha256=MBP34Juj-3JGJj6-XFzTaLhPZztQGk2tpONH8AvUX48,3638
|
|
7
|
+
bounded_subprocess-2.0.0.dist-info/METADATA,sha256=ckc2wxHahQwumKGSuDrhSsDg5wH1Z7-fLgHnpkaqzkU,2664
|
|
8
|
+
bounded_subprocess-2.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
bounded_subprocess-2.0.0.dist-info/licenses/LICENSE.txt,sha256=UVerBV0_1vMFt8QkaXuVnZVSlOiKDiBSieK5MNLy4Ls,1086
|
|
10
|
+
bounded_subprocess-2.0.0.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
bounded_subprocess/__init__.py,sha256=PHsdbPdGYopVQH_KG8vdpifyt8ZuCLd0h_JeMRCPNdI,855
|
|
2
|
-
bounded_subprocess/bounded_subprocess_async.py,sha256=uvwMhB0OSJ91qJXVFlIzWfNQXQzw9I8WV7RdNzNWVDc,1158
|
|
3
|
-
bounded_subprocess/interactive.py,sha256=Vn-002fH6rAekOwugGqdZUZ3O3x1wY-mLxApBtyC-DA,5016
|
|
4
|
-
bounded_subprocess/interactive_async.py,sha256=igxFfeC7zdQxX34-pQRlTNgYIpSbVFgmGYCCvpwsMPw,5085
|
|
5
|
-
bounded_subprocess/util.py,sha256=MBP34Juj-3JGJj6-XFzTaLhPZztQGk2tpONH8AvUX48,3638
|
|
6
|
-
bounded_subprocess-1.5.0.dist-info/METADATA,sha256=FA0SjIq_lciG1NrdOXjF29tCXIKAuCFO2WyiAlkwkdI,2664
|
|
7
|
-
bounded_subprocess-1.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
bounded_subprocess-1.5.0.dist-info/licenses/LICENSE.txt,sha256=UVerBV0_1vMFt8QkaXuVnZVSlOiKDiBSieK5MNLy4Ls,1086
|
|
9
|
-
bounded_subprocess-1.5.0.dist-info/RECORD,,
|
|
File without changes
|
{bounded_subprocess-1.5.0.dist-info → bounded_subprocess-2.0.0.dist-info}/licenses/LICENSE.txt
RENAMED
|
File without changes
|