worker: use pyon

This commit is contained in:
Sebastien Bourdeauducq 2014-10-25 16:31:34 +08:00
parent 3f1391f7f2
commit 6ac3c5d8ae
2 changed files with 9 additions and 7 deletions

View File

@ -2,7 +2,8 @@ import sys
import asyncio
import subprocess
import signal
import json
from artiq.management import pyon
class WorkerFailed(Exception):
@ -24,7 +25,7 @@ class Worker:
@asyncio.coroutine
def _send(self, obj, timeout):
line = json.dumps(obj)
line = pyon.encode(obj)
self.process.stdin.write(line.encode())
self.process.stdin.write("\n".encode())
try:
@ -47,9 +48,9 @@ class Worker:
raise WorkerFailed(
"Worker ended unexpectedly while trying to receive data")
try:
obj = json.loads(line.decode())
obj = pyon.decode(line.decode())
except:
raise WorkerFailed("Worker sent invalid JSON data")
raise WorkerFailed("Worker sent invalid PYON data")
return obj
@asyncio.coroutine

View File

@ -1,7 +1,8 @@
import json
import sys
import importlib
from artiq.management import pyon
def import_in_folder(path, name):
try:
@ -20,7 +21,7 @@ def run(path, name):
def put_object(obj):
ds = json.dumps(obj)
ds = pyon.encode(obj)
sys.__stdout__.write(ds)
sys.__stdout__.write("\n")
sys.__stdout__.flush()
@ -31,7 +32,7 @@ def main():
while True:
line = sys.__stdin__.readline()
obj = json.loads(line)
obj = pyon.decode(line)
put_object("ack")
try: