Ejemplo n.º 1
0
 def readline(self):
     # Delayed open
     if (self.obs_pipe is None):
         print('PipeIo.readline: Opening OBS pipe [{}]'.format(
             self.obs_pipe_filename))
         try:
             with Timeout(
                     1200
             ):  # Should be long enough to finish one episode for execution of non-RL model
                 self.obs_pipe = open(self.obs_pipe_filename, 'r')
         except Timeout.Timeout:
             print('Opening file {} timed out'.format(
                 self.obs_pipe_filename))
             return ''
     while True:
         line = self.obs_pipe.readline()[:-1]
         if (line == ''):
             return line
         items = line.split(',', 1)
         if (len(items) == 2):
             break
     seq = int(items[0])
     val = float(items[1])
     assert (self.obs_seq == seq)
     self.obs_seq += 1
     return val
Ejemplo n.º 2
0
 def writeline(self, str):
     # Delayed open
     if (self.act_pipe is None):
         try:
             with Timeout(1):
                 self.act_pipe = open(self.act_pipe_filename, 'w')
         except Timeout.Timeout:
             print('Opening file {} timed out'.format(
                 self.act_pipe_filename))
             return True
         print('PipeIo.writeline: Opened ACT pipe {}'.format(
             self.act_pipe_filename))
     line = '{0:d},{1:s}'.format(self.act_seq, str)
     self.act_pipe.write('{}\n'.format(line))
     self.act_seq += 1
     return False