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

View File

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