in support/gym_remote/server.py [0:0]
def serve(self, timestep_limit=None, wallclock_limit=None, ignore_reset=False):
if wallclock_limit is not None:
end = time.time() + wallclock_limit
self.bridge.settimeout(wallclock_limit)
else:
end = None
ts = 0
try:
self.bridge.server_accept()
except Bridge.Timeout:
return ts
done = True
while timestep_limit is None or ts < timestep_limit:
if wallclock_limit:
t = time.time()
if t >= end:
self.bridge.close(exception=gre.WallClockTimeoutError)
break
self.bridge.settimeout(end - t)
try:
self.bridge.recv()
except Bridge.Timeout:
self.bridge.close(exception=gre.WallClockTimeoutError)
break
except Bridge.Closed:
self.bridge.close(exception=gre.ClientDisconnectError)
break
if self.ch_reset.value:
if ignore_reset and not done:
self.bridge.exception(gre.ResetError)
self.bridge.send()
continue
self.ch_ob.value = self.env.reset()
self.ch_reset.value = False
self.ch_reward.value = 0
self.ch_done.value = False
done = False
else:
if ignore_reset and done:
self.bridge.exception(gre.ResetError)
self.bridge.send()
continue
ob, rew, done, _ = self.env.step(self.ch_ac.value)
self.ch_ob.value = ob
self.ch_reward.value = rew
self.ch_done.value = done
self.bridge.send()
ts += 1
if timestep_limit and ts >= timestep_limit:
self.bridge.close(exception=gre.TimestepTimeoutError)
return ts