File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,15 @@ def __init__( # noqa: C901
249
249
assert self .process .stdin is not None
250
250
if "r" in mode :
251
251
self .in_pipe = self .process .stdin
252
+ # A python subprocess can read and write from pipes, but not from
253
+ # Python in-memory objects. In order for a program to read from an
254
+ # in-memory object, a pipe must be created. This pipe must be fed
255
+ # data from the in-memory object. This must be done in a separate
256
+ # thread, because IO operations will block when the pipe is full
257
+ # when writing, or empty when reading. Since the quantity of output
258
+ # data generated by a certain amount of input data is unknown, the
259
+ # only way to prevent a blocking application is to write
260
+ # data continuously to the process stdin on another thread.
252
261
self .in_thread = threading .Thread (target = self ._feed_pipe )
253
262
self .in_thread .start ()
254
263
self ._file : BinaryIO = self .process .stdout # type: ignore
You can’t perform that action at this time.
0 commit comments