Skip to content

Commit 591e44b

Browse files
committedAug 4, 2016
gui/applets: capture applet stdout/stderr and redirect to log. Closes #472
1 parent f183f87 commit 591e44b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed
 

Diff for: ‎artiq/gui/applets.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import sys
44
import string
55
import shlex
6+
import os
7+
import subprocess
68
from functools import partial
79
from itertools import count
810

911
from PyQt5 import QtCore, QtGui, QtWidgets
1012

1113
from artiq.protocols.pipe_ipc import AsyncioParentComm
14+
from artiq.protocols.logging import LogParser
1215
from artiq.protocols import pyon
1316
from artiq.gui.tools import QDockWidgetCloseDetect
1417

@@ -106,6 +109,9 @@ def rename(self, name):
106109
self.applet_name = name
107110
self.setWindowTitle("Applet: " + name)
108111

112+
def _get_log_source(self):
113+
return "applet({})".format(self.applet_name)
114+
109115
async def start(self):
110116
if self.starting_stopping:
111117
return
@@ -121,12 +127,22 @@ async def start(self):
121127
ipc_address=self.ipc.get_address().replace("\\", "\\\\")
122128
)
123129
logger.debug("starting command %s for %s", command, self.applet_name)
130+
env = os.environ.copy()
131+
env["PYTHONUNBUFFERED"] = "1"
124132
try:
125-
await self.ipc.create_subprocess(*shlex.split(command),
126-
start_new_session=True)
133+
await self.ipc.create_subprocess(
134+
*shlex.split(command),
135+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
136+
env=env, start_new_session=True)
127137
except:
128138
logger.warning("Applet %s failed to start", self.applet_name,
129139
exc_info=True)
140+
asyncio.ensure_future(
141+
LogParser(self._get_log_source).stream_task(
142+
self.ipc.process.stdout))
143+
asyncio.ensure_future(
144+
LogParser(self._get_log_source).stream_task(
145+
self.ipc.process.stderr))
130146
self.ipc.start(self.embed, self.fix_initial_size)
131147
finally:
132148
self.starting_stopping = False

0 commit comments

Comments
 (0)
Please sign in to comment.