forked from M-Labs/artiq
worker: use pyon
This commit is contained in:
parent
3f1391f7f2
commit
6ac3c5d8ae
|
@ -2,7 +2,8 @@ import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
import subprocess
|
import subprocess
|
||||||
import signal
|
import signal
|
||||||
import json
|
|
||||||
|
from artiq.management import pyon
|
||||||
|
|
||||||
|
|
||||||
class WorkerFailed(Exception):
|
class WorkerFailed(Exception):
|
||||||
|
@ -24,7 +25,7 @@ class Worker:
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _send(self, obj, timeout):
|
def _send(self, obj, timeout):
|
||||||
line = json.dumps(obj)
|
line = pyon.encode(obj)
|
||||||
self.process.stdin.write(line.encode())
|
self.process.stdin.write(line.encode())
|
||||||
self.process.stdin.write("\n".encode())
|
self.process.stdin.write("\n".encode())
|
||||||
try:
|
try:
|
||||||
|
@ -47,9 +48,9 @@ class Worker:
|
||||||
raise WorkerFailed(
|
raise WorkerFailed(
|
||||||
"Worker ended unexpectedly while trying to receive data")
|
"Worker ended unexpectedly while trying to receive data")
|
||||||
try:
|
try:
|
||||||
obj = json.loads(line.decode())
|
obj = pyon.decode(line.decode())
|
||||||
except:
|
except:
|
||||||
raise WorkerFailed("Worker sent invalid JSON data")
|
raise WorkerFailed("Worker sent invalid PYON data")
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import json
|
|
||||||
import sys
|
import sys
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
|
from artiq.management import pyon
|
||||||
|
|
||||||
|
|
||||||
def import_in_folder(path, name):
|
def import_in_folder(path, name):
|
||||||
try:
|
try:
|
||||||
|
@ -20,7 +21,7 @@ def run(path, name):
|
||||||
|
|
||||||
|
|
||||||
def put_object(obj):
|
def put_object(obj):
|
||||||
ds = json.dumps(obj)
|
ds = pyon.encode(obj)
|
||||||
sys.__stdout__.write(ds)
|
sys.__stdout__.write(ds)
|
||||||
sys.__stdout__.write("\n")
|
sys.__stdout__.write("\n")
|
||||||
sys.__stdout__.flush()
|
sys.__stdout__.flush()
|
||||||
|
@ -31,7 +32,7 @@ def main():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = sys.__stdin__.readline()
|
line = sys.__stdin__.readline()
|
||||||
obj = json.loads(line)
|
obj = pyon.decode(line)
|
||||||
put_object("ack")
|
put_object("ack")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue