diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/server/moses.py | 10 | ||||
-rwxr-xr-x | scripts/server/sim-pe.py | 57 |
2 files changed, 54 insertions, 13 deletions
diff --git a/scripts/server/moses.py b/scripts/server/moses.py index 155458b9b..a176c473a 100644 --- a/scripts/server/moses.py +++ b/scripts/server/moses.py @@ -152,7 +152,7 @@ def find_free_port(p): class MosesServer(ProcessWrapper): - def __init__(self,args=["-fd", "\n"]): + def __init__(self,args=[]): self.process = None mserver_cmd = moses_root+"/bin/mosesserver" self.cmd = [mserver_cmd] + args @@ -175,7 +175,10 @@ class MosesServer(ProcessWrapper): self.cmd.extend(["--server-port", "%d"%self.port]) if debug: print >>sys.stderr,self.cmd - self.process = Popen(self.cmd,stderr = sys.stderr) + # self.stderr = open("mserver.%d.stderr"%self.port,'w') + # self.stdout = open("mserver.%d.stdout"%self.port,'w') + # self.process = Popen(self.cmd,stderr = self.stderr,stdout = self.stdout) + self.process = Popen(self.cmd) else: devnull = open(os.devnull,"w") self.process = Popen(self.cmd, stderr=devnull, stdout=devnull) @@ -216,10 +219,13 @@ class MosesServer(ProcessWrapper): elif type(input) is list: return [self.translate(x) for x in input] + elif type(input) is dict: return self.proxy.translate(input) + else: raise Exception("Can't handle input of this type!") + except: attempts += 1 print >>sys.stderr, "WAITING", attempts diff --git a/scripts/server/sim-pe.py b/scripts/server/sim-pe.py index 340695a56..52d1e314a 100755 --- a/scripts/server/sim-pe.py +++ b/scripts/server/sim-pe.py @@ -127,13 +127,40 @@ def translate(proxy, args, line): param['nbest-distinct'] = True pass attempts = 0 - while attempts < 120: + while attempts < 20: + t1 = time.time() try: - return proxy.translate(param) - except: - print >>sys.stderr, "Waiting", proxy - attempts += 1 + return proxy.translate(param) + + # except xmlrpclib.Fault as e: + # except xmlrpclib.ProtocolError as e: + # except xmlrpclib.ResponseError as e: + except xmlrpclib.Error as e: + time.sleep(2) # give all the stderr stuff a chance to be flushed + print >>sys.stderr," XMLRPC error:",e + print >>sys.stderr, "Input was" + print >>sys.stderr, param + sys.exit(1) + + except IOError as e: + print >>sys.stderr,"I/O error({0}): {1}".format(e.errno, e.strerror) time.sleep(5) + + except: + serverstatus = mserver.process.poll() + if serverstatus == None: + print >>sys.stderr, "Connection failed after %f seconds"%(time.time()-t1) + attempts += 1 + if attempts > 10: + time.sleep(10) + else: + time.sleep(5) + pass + else: + + print >>sys.stderr, "Oopsidaisy, server exited with code %d (signal %d)"\ + %(serverstatus/256,serverstatus%256) + pass pass pass raise Exception("Exception: could not reach translation server.") @@ -210,17 +237,25 @@ if __name__ == "__main__": pass pass - if args.url: - mserver.connect(args.url) - else: - mserver.start(args=mo_args,port=args.port,debug=args.debug) - pass - ref = None aln = None if args.ref: ref = read_data(args.ref) if args.aln: aln = read_data(args.aln) + if ref and aln: + try: + mo_args.index("--serial") + except: + mo_args.append("--serial") + pass + pass + + if args.url: + mserver.connect(args.url) + else: + mserver.start(args=mo_args, port=args.port, debug=args.debug) + pass + if (args.input == "-"): line = sys.stdin.readline() idx = 0 |