回答編集履歴
1
追記
test
CHANGED
@@ -115,3 +115,139 @@
|
|
115
115
|
参考:
|
116
116
|
|
117
117
|
[python でコマンド実行。サブプロセスの終了待ち・強制終了・親プロセスと一緒に殺す。 - それマグで!](http://takuya-1st.hatenablog.jp/entry/2016/04/11/044313)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
### 追記
|
122
|
+
|
123
|
+
どうせpythonプログラムを呼ぶなら、スレッドという手もあります。引数や返り値を扱いたければメリットがあるかもしれません。
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
**main.py**
|
128
|
+
|
129
|
+
```python
|
130
|
+
|
131
|
+
import time
|
132
|
+
|
133
|
+
from threading import Thread
|
134
|
+
|
135
|
+
import subb
|
136
|
+
|
137
|
+
import subc
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
thlst = []
|
142
|
+
|
143
|
+
for count in range(3):
|
144
|
+
|
145
|
+
print("Hello!")
|
146
|
+
|
147
|
+
th = Thread(target=subb.main)
|
148
|
+
|
149
|
+
th.start()
|
150
|
+
|
151
|
+
thlst.append(th)
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
print("A")
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
time.sleep(3)
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
th = Thread(target=subc.main)
|
164
|
+
|
165
|
+
th.start()
|
166
|
+
|
167
|
+
thlst.append(th)
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
print("D")
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
for th in thlst:
|
176
|
+
|
177
|
+
th.join()
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
**subb.py**
|
184
|
+
|
185
|
+
```python
|
186
|
+
|
187
|
+
import time
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
def main():
|
192
|
+
|
193
|
+
#Call me?を出力
|
194
|
+
|
195
|
+
print("Call me?")
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
#5秒停止
|
200
|
+
|
201
|
+
time.sleep(5)
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
#Bを出力
|
206
|
+
|
207
|
+
print("B")
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
if __name__ == "__main__":
|
212
|
+
|
213
|
+
main()
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
**subc.py**
|
222
|
+
|
223
|
+
```python
|
224
|
+
|
225
|
+
import time
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
def main():
|
230
|
+
|
231
|
+
#What happened?を出力
|
232
|
+
|
233
|
+
print("What happened?")
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
#5秒停止
|
238
|
+
|
239
|
+
time.sleep(5)
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
#Cを出力
|
244
|
+
|
245
|
+
print("C")
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
if __name__ == "__main__":
|
250
|
+
|
251
|
+
main()
|
252
|
+
|
253
|
+
```
|