@@ -290,8 +290,9 @@ def _convert_line(lne):
290
290
def process_output (myproc , out_to_screen , spinner , cmpl , out_queue ):
291
291
line = b''
292
292
err_line = b''
293
-
294
293
last_line_len = - 1
294
+ line_updated = False
295
+ err_updated = False
295
296
296
297
event = threading .Event ()
297
298
@@ -303,23 +304,29 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
303
304
t = None
304
305
305
306
while True :
306
- if myproc .poll () is not None :
307
- break
308
-
309
307
# --- extract line using read(1)
310
308
out = myproc .stdout .read (1 )
311
309
while out :
310
+ line_updated = True
312
311
line += out
313
312
if out == b'\n ' :
314
313
line = _convert_line (line .strip ())
315
314
if not line :
316
315
line = b''
317
- continue
316
+ break
318
317
319
318
out_queue .put (line )
320
319
321
320
if not spinner and out_to_screen :
322
- if cmpl and (line .startswith ('[' ) or line .startswith ('--' )):
321
+ if (
322
+ cmpl and (
323
+ line .startswith ('[' ) or
324
+ (
325
+ line .startswith ('--' ) and
326
+ len (line ) <= 80
327
+ )
328
+ )
329
+ ):
323
330
if last_line_len != - 1 :
324
331
sys .stdout .write ('\r ' )
325
332
@@ -346,6 +353,7 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
346
353
out = myproc .stderr .read (1 )
347
354
348
355
while out :
356
+ err_updated = True
349
357
if not spinner and out_to_screen and cmpl and last_line_len != - 1 :
350
358
sys .stdout .write ('\n ' )
351
359
sys .stdout .flush ()
@@ -356,7 +364,7 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
356
364
err_line = _convert_line (err_line .strip ())
357
365
if not err_line :
358
366
err_line = b''
359
- continue
367
+ break
360
368
361
369
out_queue .put (err_line )
362
370
if out_to_screen and not spinner :
@@ -367,6 +375,13 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
367
375
368
376
out = myproc .stderr .read (1 )
369
377
378
+ if not err_updated and not line_updated :
379
+ if myproc .poll () is not None :
380
+ break
381
+
382
+ err_updated = False
383
+ line_updated = False
384
+
370
385
if t is not None :
371
386
event .set ()
372
387
t .join ()
@@ -387,46 +402,54 @@ def spawn(cmd_, out_to_screen=True, spinner=False, env=None, cmpl=False):
387
402
if isinstance (cmd_ [0 ], str ):
388
403
cmd_ = [cmd_ [:]]
389
404
390
- cmd_ = ' && ' .join (' ' .join (c ) for c in cmd_ )
391
-
392
- if sys .platform .startswith ('darwin' ):
393
- if cmd_ .startswith ('make ' ):
394
- cmd_ = 'g' + cmd_
395
-
396
- if ' make ' in cmd_ :
397
- cmd_ = cmd_ .replace (' make ' , ' gmake ' )
398
-
399
- if 'GITHUB_RUN_ID' in os .environ :
400
- print (cmd_ )
405
+ cmd_ = list (' ' .join (c ) for c in cmd_ )
401
406
402
407
que = queue .Queue ()
403
408
404
409
p = subprocess .Popen (
405
- cmd_ ,
410
+ 'bash' ,
406
411
stdout = subprocess .PIPE ,
407
412
stderr = subprocess .PIPE ,
413
+ stdin = subprocess .PIPE ,
408
414
shell = True ,
409
415
env = env
410
416
)
411
417
418
+ os .set_blocking (p .stdout .fileno (), False )
419
+ os .set_blocking (p .stderr .fileno (), False )
420
+
412
421
proc_thread = threading .Thread (
413
422
target = process_output ,
414
423
args = (p , out_to_screen , spinner , cmpl , que )
415
424
)
416
425
417
426
proc_thread .start ()
418
-
419
427
output_buffer = []
420
428
429
+ while cmd_ :
430
+ item = cmd_ .pop (0 )
431
+ if sys .platform .startswith ('darwin' ):
432
+ if item .startswith ('make ' ):
433
+ item = 'g' + item
434
+
435
+ if ' make ' in item :
436
+ item = item .replace (' make ' , ' gmake ' )
437
+
438
+ if 'GITHUB_RUN_ID' in os .environ :
439
+ print (item )
440
+
441
+ p .stdin .write (item .encode ('utf-8' ) + b'\n ' )
442
+
443
+ p .stdin .close ()
444
+
421
445
while proc_thread and proc_thread .is_alive (): # wait for thread to finish
422
446
try :
423
447
line = que .get_nowait () # or q.get(timeout=.1)
424
448
output_buffer .append (line )
425
449
except queue .Empty :
426
450
pass
427
-
428
451
try :
429
- proc_thread .join (1 )
452
+ proc_thread .join (0.025 )
430
453
except : # NOQA
431
454
break
432
455
0 commit comments