@@ -61,6 +61,33 @@ def __init__(self, test_class: unittest.TestCase,
61
61
self .test_class .output = None
62
62
self .execution_time = None
63
63
64
+ def form_daemon_process (self , cmdline , env ):
65
+ def stream_output (stream : subprocess .PIPE ) -> None :
66
+ try :
67
+ for line in iter (stream .readline , '' ):
68
+ print (line )
69
+ self .test_class .output += line
70
+ finally :
71
+ stream .close ()
72
+
73
+ self .process = subprocess .Popen (
74
+ cmdline ,
75
+ stdout = subprocess .PIPE ,
76
+ stderr = subprocess .PIPE ,
77
+ text = True ,
78
+ env = env
79
+ )
80
+ logging .info (f"Process started in background with PID: { self .process .pid } " )
81
+
82
+ if self .process .stdout and self .process .stderr :
83
+ stdout_thread = threading .Thread (target = stream_output , args = (self .process .stdout ,), daemon = True )
84
+ stderr_thread = threading .Thread (target = stream_output , args = (self .process .stderr ,), daemon = True )
85
+
86
+ stdout_thread .start ()
87
+ stderr_thread .start ()
88
+
89
+ return self .process .pid
90
+
64
91
def run (self , command , gdb = False , old_binary = False , return_id = True , env = None ,
65
92
skip_log_directory = False , expect_error = False , use_backup_dir = True , daemonize = False ):
66
93
"""
@@ -120,29 +147,7 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
120
147
121
148
start_time = time .time ()
122
149
if daemonize :
123
-
124
- def stream_output (stream : subprocess .PIPE ) -> None :
125
- for line in iter (stream .readline , '' ):
126
- print (line )
127
- self .test_class .output += line
128
- stream .close ()
129
-
130
- self .process = subprocess .Popen (
131
- cmdline ,
132
- stdout = subprocess .PIPE ,
133
- stderr = subprocess .PIPE ,
134
- text = True ,
135
- env = env
136
- )
137
- logging .info (f"Process started in background with PID: { self .process .pid } " )
138
-
139
- if self .process .stdout and self .process .stderr :
140
- stdout_thread = threading .Thread (target = stream_output , args = (self .process .stdout ,))
141
- stderr_thread = threading .Thread (target = stream_output , args = (self .process .stderr ,))
142
-
143
- stdout_thread .start ()
144
- stderr_thread .start ()
145
- return self .process .pid
150
+ return self .form_daemon_process (cmdline , env )
146
151
else :
147
152
self .test_class .output = subprocess .check_output (
148
153
cmdline ,
0 commit comments