diff --git a/src/mc_wrapper.py b/src/mc_wrapper.py index f97a3fe..ee75ff8 100644 --- a/src/mc_wrapper.py +++ b/src/mc_wrapper.py @@ -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: - 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 if not output: await asyncio.sleep(1) diff --git a/src/nbsr.py b/src/nbsr.py index 74f2a03..f8168ed 100644 --- a/src/nbsr.py +++ b/src/nbsr.py @@ -46,6 +46,11 @@ class NonBlockingStreamReader: return self._q.get(block = timeout is not None, timeout = timeout) except Empty: - return None + if self._t.is_alive(): + return None + else: + raise ProcessHasTerminated -class UnexpectedEndOfStream(Exception): pass \ No newline at end of file +class UnexpectedEndOfStream(Exception): pass + +class ProcessHasTerminated(Exception): pass