File tree 2 files changed +23
-6
lines changed
2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -484,19 +484,19 @@ Protocol classes can implement the following **callback methods**:
484
484
:widths: 50 50
485
485
:class: full-width-table
486
486
487
- * - ``callback `` :meth: `pipe_data_received()
488
- <SubprocessProtocol.pipe_data_received> `
487
+ * - ``callback `` :meth: `~SubprocessProtocol.pipe_data_received `
489
488
- Called when the child process writes data into its
490
489
*stdout * or *stderr * pipe.
491
490
492
- * - ``callback `` :meth: `pipe_connection_lost()
493
- <SubprocessProtocol.pipe_connection_lost> `
491
+ * - ``callback `` :meth: `~SubprocessProtocol.pipe_connection_lost `
494
492
- Called when one of the pipes communicating with
495
493
the child process is closed.
496
494
497
495
* - ``callback `` :meth: `process_exited()
498
496
<SubprocessProtocol.process_exited> `
499
- - Called when the child process has exited.
497
+ - Called when the child process has exited. It can be called before
498
+ :meth: `~SubprocessProtocol.pipe_data_received ` and
499
+ :meth: `~SubprocessProtocol.pipe_connection_lost ` methods.
500
500
501
501
502
502
Event Loop Policies
Original file line number Diff line number Diff line change @@ -708,6 +708,9 @@ factories passed to the :meth:`loop.subprocess_exec` and
708
708
709
709
Called when the child process has exited.
710
710
711
+ It can be called before :meth: `~SubprocessProtocol.pipe_data_received ` and
712
+ :meth: `~SubprocessProtocol.pipe_connection_lost ` methods.
713
+
711
714
712
715
Examples
713
716
========
@@ -1003,12 +1006,26 @@ The subprocess is created by the :meth:`loop.subprocess_exec` method::
1003
1006
def __init__(self, exit_future):
1004
1007
self.exit_future = exit_future
1005
1008
self.output = bytearray()
1009
+ self.pipe_closed = False
1010
+ self.exited = False
1011
+
1012
+ def pipe_connection_lost(self, fd, exc):
1013
+ self.pipe_closed = True
1014
+ self.check_for_exit()
1006
1015
1007
1016
def pipe_data_received(self, fd, data):
1008
1017
self.output.extend(data)
1009
1018
1010
1019
def process_exited(self):
1011
- self.exit_future.set_result(True)
1020
+ self.exited = True
1021
+ # process_exited() method can be called before
1022
+ # pipe_connection_lost() method: wait until both methods are
1023
+ # called.
1024
+ self.check_for_exit()
1025
+
1026
+ def check_for_exit(self):
1027
+ if self.pipe_closed and self.exited:
1028
+ self.exit_future.set_result(True)
1012
1029
1013
1030
async def get_date():
1014
1031
# Get a reference to the event loop as we plan to use
You can’t perform that action at this time.
0 commit comments