stouputils 1.19.2__py3-none-any.whl → 1.19.4__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.
- stouputils/parallel/capturer.py +17 -9
- stouputils/parallel/capturer.pyi +15 -5
- {stouputils-1.19.2.dist-info → stouputils-1.19.4.dist-info}/METADATA +1 -1
- {stouputils-1.19.2.dist-info → stouputils-1.19.4.dist-info}/RECORD +6 -6
- {stouputils-1.19.2.dist-info → stouputils-1.19.4.dist-info}/WHEEL +0 -0
- {stouputils-1.19.2.dist-info → stouputils-1.19.4.dist-info}/entry_points.txt +0 -0
stouputils/parallel/capturer.py
CHANGED
|
@@ -27,13 +27,23 @@ class CaptureOutput:
|
|
|
27
27
|
The class creates an os.pipe(), marks fds as inheritable (for spawn method),
|
|
28
28
|
provides methods to start a listener thread that reads from the pipe and writes
|
|
29
29
|
to the main process's sys.stdout/sys.stderr, and to close/join the listener.
|
|
30
|
+
|
|
31
|
+
>>> capturer = CaptureOutput(encoding="utf-8", errors="replace")
|
|
32
|
+
|
|
33
|
+
>>> pass # send capturer object to subprocess
|
|
34
|
+
>>> capturer.redirect() # Redirects sys.stdout/sys.stderr to the pipe
|
|
35
|
+
|
|
36
|
+
>>> pass # in parent process:
|
|
37
|
+
>>> #capturer.parent_close_write() # Close parent's write end
|
|
38
|
+
>>> capturer.start_listener() # Start listener thread to read from pipe
|
|
39
|
+
>>> ... # do other work
|
|
40
|
+
>>> capturer.join_listener(timeout=0.1) # Wait for listener to finish (on EOF)
|
|
30
41
|
"""
|
|
31
|
-
def __init__(self, encoding: str = "utf-8", errors: str = "replace"
|
|
42
|
+
def __init__(self, encoding: str = "utf-8", errors: str = "replace"):
|
|
32
43
|
import multiprocessing as mp
|
|
33
44
|
import threading
|
|
34
45
|
self.encoding: str = encoding
|
|
35
46
|
self.errors: str = errors
|
|
36
|
-
self.chunk_size: int = chunk_size
|
|
37
47
|
self.read_conn, self.write_conn = mp.Pipe(duplex=False)
|
|
38
48
|
self.read_fd = self.read_conn.fileno()
|
|
39
49
|
self.write_fd = self.write_conn.fileno()
|
|
@@ -91,10 +101,11 @@ class CaptureOutput:
|
|
|
91
101
|
nonlocal buffer
|
|
92
102
|
try:
|
|
93
103
|
while True:
|
|
94
|
-
# Read
|
|
104
|
+
# Read the next message from the pipe. Use recv_bytes() without a maxlength
|
|
105
|
+
# so we don't error when a single message is larger than our chunk size.
|
|
95
106
|
try:
|
|
96
|
-
data: bytes = self.read_conn.recv_bytes(
|
|
97
|
-
except EOFError:
|
|
107
|
+
data: bytes = self.read_conn.recv_bytes()
|
|
108
|
+
except (EOFError, OSError, BrokenPipeError):
|
|
98
109
|
_handle_buffer()
|
|
99
110
|
break
|
|
100
111
|
|
|
@@ -104,10 +115,7 @@ class CaptureOutput:
|
|
|
104
115
|
except Exception:
|
|
105
116
|
chunk = data.decode(self.encoding, errors="replace")
|
|
106
117
|
buffer += chunk
|
|
107
|
-
|
|
108
|
-
# Periodically flush large buffers to avoid holding too much memory
|
|
109
|
-
if len(buffer) > self.chunk_size * 4:
|
|
110
|
-
_handle_buffer()
|
|
118
|
+
_handle_buffer()
|
|
111
119
|
finally:
|
|
112
120
|
safe_close(self.read_conn)
|
|
113
121
|
self.read_fd = -1
|
stouputils/parallel/capturer.pyi
CHANGED
|
@@ -12,20 +12,30 @@ class PipeWriter:
|
|
|
12
12
|
def flush(self) -> None: ...
|
|
13
13
|
|
|
14
14
|
class CaptureOutput:
|
|
15
|
-
|
|
15
|
+
''' Utility to capture stdout/stderr from a subprocess and relay it to the parent\'s stdout.
|
|
16
16
|
|
|
17
17
|
\tThe class creates an os.pipe(), marks fds as inheritable (for spawn method),
|
|
18
18
|
\tprovides methods to start a listener thread that reads from the pipe and writes
|
|
19
|
-
\tto the main process's sys.stdout/sys.stderr, and to close/join the listener.
|
|
20
|
-
|
|
19
|
+
\tto the main process\'s sys.stdout/sys.stderr, and to close/join the listener.
|
|
20
|
+
|
|
21
|
+
\t>>> capturer = CaptureOutput(encoding="utf-8", errors="replace")
|
|
22
|
+
|
|
23
|
+
\t>>> pass # send capturer object to subprocess
|
|
24
|
+
\t>>> capturer.redirect() # Redirects sys.stdout/sys.stderr to the pipe
|
|
25
|
+
|
|
26
|
+
\t>>> pass # in parent process:
|
|
27
|
+
\t>>> #capturer.parent_close_write() # Close parent\'s write end
|
|
28
|
+
\t>>> capturer.start_listener() # Start listener thread to read from pipe
|
|
29
|
+
\t>>> ... # do other work
|
|
30
|
+
\t>>> capturer.join_listener(timeout=0.1) # Wait for listener to finish (on EOF)
|
|
31
|
+
\t'''
|
|
21
32
|
encoding: str
|
|
22
33
|
errors: str
|
|
23
|
-
chunk_size: int
|
|
24
34
|
read_fd: Incomplete
|
|
25
35
|
write_fd: Incomplete
|
|
26
36
|
_thread: threading.Thread | None
|
|
27
37
|
_reader_file: IO[Any] | None
|
|
28
|
-
def __init__(self, encoding: str = 'utf-8', errors: str = 'replace'
|
|
38
|
+
def __init__(self, encoding: str = 'utf-8', errors: str = 'replace') -> None: ...
|
|
29
39
|
def __repr__(self) -> str: ...
|
|
30
40
|
def __getstate__(self) -> dict[str, Any]: ...
|
|
31
41
|
def redirect(self) -> None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: stouputils
|
|
3
|
-
Version: 1.19.
|
|
3
|
+
Version: 1.19.4
|
|
4
4
|
Summary: Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more.
|
|
5
5
|
Keywords: utilities,tools,helpers,development,python
|
|
6
6
|
Author: Stoupy51
|
|
@@ -141,8 +141,8 @@ stouputils/lock/shared.py,sha256=G8Mcy7dXtNESyU7hSaeihNrCU4l98VhyQyO_vQYPJ7g,788
|
|
|
141
141
|
stouputils/lock/shared.pyi,sha256=0CV6TpTaDEkcGA35Q-ijp8ckImZ32umlMA4U-8C_O-I,545
|
|
142
142
|
stouputils/parallel/__init__.py,sha256=myD8KiVfPPKF26Xu8Clu0p-VaYDK74loMUjUkl6-9XU,1013
|
|
143
143
|
stouputils/parallel/__init__.pyi,sha256=UtZKtl9i__OH0Edypap9oZUcTF1h91qfpItG1-x7TfE,97
|
|
144
|
-
stouputils/parallel/capturer.py,sha256=
|
|
145
|
-
stouputils/parallel/capturer.pyi,sha256=
|
|
144
|
+
stouputils/parallel/capturer.py,sha256=s4x_o8Awe-RYyyYxTzgQSm1N2shDjFhENkJBdW-WHEY,4574
|
|
145
|
+
stouputils/parallel/capturer.pyi,sha256=UdhhJFdyBsBUyEAltaG3Im13GvZlNXi-ScQDXezFI1Q,2141
|
|
146
146
|
stouputils/parallel/common.py,sha256=niDcAiEX3flX0ow91gXOB4umlOrR8PIYvpcKPClJHfM,4910
|
|
147
147
|
stouputils/parallel/common.pyi,sha256=jbyftOYHKP2qaA8YC1f1f12-BDBkhfsQsnPdsR4oet8,2493
|
|
148
148
|
stouputils/parallel/multi.py,sha256=tHJgcQJwsI6QeKEHoGJC4tsVK_6t1Fazkb06i1u-W_8,12610
|
|
@@ -156,7 +156,7 @@ stouputils/typing.py,sha256=9sj6-_lW9pyQFmxW2K1SinGCy7IWeRouUfWjPU2qDsk,2205
|
|
|
156
156
|
stouputils/typing.pyi,sha256=XRKhGA7jWjcE-DtS2UznevBxBIFqj8IZI8-J48_3GQc,1341
|
|
157
157
|
stouputils/version_pkg.py,sha256=Jsp-s03L14DkiZ94vQgrlQmaxApfn9DC8M_nzT1SJLk,7014
|
|
158
158
|
stouputils/version_pkg.pyi,sha256=QPvqp1U3QA-9C_CC1dT9Vahv1hXEhstbM7x5uzMZSsQ,755
|
|
159
|
-
stouputils-1.19.
|
|
160
|
-
stouputils-1.19.
|
|
161
|
-
stouputils-1.19.
|
|
162
|
-
stouputils-1.19.
|
|
159
|
+
stouputils-1.19.4.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
|
|
160
|
+
stouputils-1.19.4.dist-info/entry_points.txt,sha256=tx0z9VOnE-sfkmbFbA93zaBMzV3XSsKEJa_BWIqUzxw,57
|
|
161
|
+
stouputils-1.19.4.dist-info/METADATA,sha256=UdM9eb2MdkC1t42azf7_UT8603Nafg0m7T9i6gERTko,13931
|
|
162
|
+
stouputils-1.19.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|