Skip to content

Commit 107e2fe

Browse files
committedJan 30, 2016
ctlmgr: reinstate lost changes
1 parent 4a29f07 commit 107e2fe

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed
 

Diff for: ‎artiq/devices/ctlmgr.py

+11-22
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from artiq.protocols.sync_struct import Subscriber
88
from artiq.protocols.pc_rpc import AsyncioClient
9-
from artiq.protocols.logging import parse_log_message, log_with_name
9+
from artiq.protocols.logging import LogParser
1010
from artiq.tools import Condition, TaskObject
1111

1212

@@ -41,14 +41,14 @@ async def call(self, method, *args, **kwargs):
4141
try:
4242
targets, _ = remote.get_rpc_id()
4343
remote.select_rpc_target(targets[0])
44-
r = await getattr(remote, method)(*args, **kwargs)
44+
r = await getattr(remote, method)()
4545
finally:
4646
remote.close_rpc()
4747
return r
4848

4949
async def _ping(self):
5050
try:
51-
ok = await asyncio.wait_for(self.call("ping"),
51+
ok = await asyncio.wait_for(self._call_controller("ping"),
5252
self.ping_timeout)
5353
if ok:
5454
self.retry_timer_cur = self.retry_timer
@@ -71,21 +71,8 @@ async def _wait_and_ping(self):
7171
else:
7272
break
7373

74-
async def forward_logs(self, stream):
75-
source = "controller({})".format(self.name)
76-
while True:
77-
try:
78-
entry = (await stream.readline())
79-
if not entry:
80-
break
81-
entry = entry[:-1]
82-
level, name, message = parse_log_message(entry.decode())
83-
log_with_name(name, level, message, extra={"source": source})
84-
except:
85-
logger.debug("exception in log forwarding", exc_info=True)
86-
break
87-
logger.debug("stopped log forwarding of stream %s of %s",
88-
stream, self.name)
74+
def _get_log_source(self):
75+
return "controller({})".format(self.name)
8976

9077
async def launcher(self):
9178
try:
@@ -96,10 +83,12 @@ async def launcher(self):
9683
self.process = await asyncio.create_subprocess_exec(
9784
*shlex.split(self.command),
9885
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
99-
asyncio.ensure_future(self.forward_logs(
100-
self.process.stdout))
101-
asyncio.ensure_future(self.forward_logs(
102-
self.process.stderr))
86+
asyncio.ensure_future(
87+
LogParser(self._get_log_source).stream_task(
88+
self.process.stdout))
89+
asyncio.ensure_future(
90+
LogParser(self._get_log_source).stream_task(
91+
self.process.stderr))
10392
await self._wait_and_ping()
10493
except FileNotFoundError:
10594
logger.warning("Controller %s failed to start", self.name)

0 commit comments

Comments
 (0)
Please sign in to comment.