def start_decoder(self): if self.child: log.writeln("stopping decoder") try: if not self.child.returncode: self.child.stdin.close() self.child.stdout.close() # "Warning: This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data." # but closing stdout means that it should get SIGPIPE if process has buffered output or writes more. so OK. self.child.wait() else: os.kill(self.child.pid, signal.SIGKILL) self.child=None except: pass self.child = Popen( [opts.decoder], cwd=opts.gars_dir, stdin=subprocess.PIPE, stdout=subprocess.PIPE) log.writeln("started decoder subprocess=%s at %s" % (self.child.pid,log.datetoday())) self.decoder_age = 0 self.oldweights = svector.Vector()
def start_decoder(self): if self.child: log.writeln("stopping decoder") try: if not self.child.returncode: self.child.stdin.close() self.child.stdout.close() # "Warning: This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data." # but closing stdout means that it should get SIGPIPE if process has buffered output or writes more. so OK. self.child.wait() else: os.kill(self.child.pid, signal.SIGKILL) self.child = None except: pass self.child = Popen([opts.decoder], cwd=opts.gars_dir, stdin=subprocess.PIPE, stdout=subprocess.PIPE) log.writeln("started decoder subprocess=%s at %s" % (self.child.pid, log.datetoday())) self.decoder_age = 0 self.oldweights = svector.Vector()
type=int, default=None) optparser.add_option("--no-shuffle", dest="shuffle_sentences", action="store_false", default=True) try: configfilename = sys.argv[1] except IndexError: sys.stderr.write( "usage: train.py config-file source-file reference-files [options...]\n" ) sys.exit(1) log.writeln("Starting at %s" % log.datetoday()) if log.level >= 1: log.write("Reading configuration from %s\n" % configfilename) execfile(configfilename) opts, args = optparser.parse_args(args=sys.argv[2:]) shuffle_sentences = opts.shuffle_sentences if opts.parallel: import parallel import mpi log.prefix = "[%s] " % parallel.rank if not opts.parallel or parallel.rank == parallel.master: infile = file(args[0])
help="fraction of sentences to hold out", type=float, default=None, ) optparser.add_option( "--heldout-sents", dest="heldout_sents", help="number of sentences to hold out", type=int, default=None ) optparser.add_option("--no-shuffle", dest="shuffle_sentences", action="store_false", default=True) try: configfilename = sys.argv[1] except IndexError: sys.stderr.write("usage: train.py config-file source-file reference-files [options...]\n") sys.exit(1) log.writeln("Starting at %s" % log.datetoday()) if log.level >= 1: log.write("Reading configuration from %s\n" % configfilename) execfile(configfilename) opts, args = optparser.parse_args(args=sys.argv[2:]) shuffle_sentences = opts.shuffle_sentences if opts.parallel: import parallel import mpi log.prefix = "[%s] " % parallel.rank if not opts.parallel or parallel.rank == parallel.master: