3
3
import sys
4
4
import string
5
5
import shlex
6
+ import os
7
+ import subprocess
6
8
from functools import partial
7
9
from itertools import count
8
10
9
11
from PyQt5 import QtCore , QtGui , QtWidgets
10
12
11
13
from artiq .protocols .pipe_ipc import AsyncioParentComm
14
+ from artiq .protocols .logging import LogParser
12
15
from artiq .protocols import pyon
13
16
from artiq .gui .tools import QDockWidgetCloseDetect
14
17
@@ -106,6 +109,9 @@ def rename(self, name):
106
109
self .applet_name = name
107
110
self .setWindowTitle ("Applet: " + name )
108
111
112
+ def _get_log_source (self ):
113
+ return "applet({})" .format (self .applet_name )
114
+
109
115
async def start (self ):
110
116
if self .starting_stopping :
111
117
return
@@ -121,12 +127,22 @@ async def start(self):
121
127
ipc_address = self .ipc .get_address ().replace ("\\ " , "\\ \\ " )
122
128
)
123
129
logger .debug ("starting command %s for %s" , command , self .applet_name )
130
+ env = os .environ .copy ()
131
+ env ["PYTHONUNBUFFERED" ] = "1"
124
132
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 )
127
137
except :
128
138
logger .warning ("Applet %s failed to start" , self .applet_name ,
129
139
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 ))
130
146
self .ipc .start (self .embed , self .fix_initial_size )
131
147
finally :
132
148
self .starting_stopping = False
0 commit comments