Allow NBSR for stderr

main
Bram van den Heuvel 2023-10-02 00:36:12 +02:00
parent 6a606a61f5
commit e94fc2d4d3
2 changed files with 17 additions and 4 deletions

View File

@ -10,7 +10,7 @@ from typing import Union
import asyncio
import json
import re
from src.nbsr import NonBlockingStreamReader as NBSR
from src.nbsr import NonBlockingStreamReader as NBSR, ProcessHasTerminated
import src.config as config
import src.build_server as build
@ -23,6 +23,7 @@ p = Popen(config.RUN_COMMAND,
stdin = PIPE, stdout = PIPE, stderr = PIPE, shell = False)
# wrap p.stdout with a NonBlockingStreamReader object:
nbsr = NBSR(p.stdout)
err_nbsr = NBSR(p.stderr)
async def start(client, mc_channel):
"""
@ -32,7 +33,14 @@ async def start(client, mc_channel):
await asyncio.sleep(3)
while True:
try:
output = nbsr.readline(0.1)
except ProcessHasTerminated:
print('==================================\nERROR LOGS :')
while True:
output = err_nbsr.readline(0.1)
print(output)
# 0.1 secs to let the shell output the result
if not output:
await asyncio.sleep(1)

View File

@ -46,6 +46,11 @@ class NonBlockingStreamReader:
return self._q.get(block = timeout is not None,
timeout = timeout)
except Empty:
if self._t.is_alive():
return None
else:
raise ProcessHasTerminated
class UnexpectedEndOfStream(Exception): pass
class ProcessHasTerminated(Exception): pass