-
Notifications
You must be signed in to change notification settings - Fork 58
/
emulator_runner.py
executable file
·36 lines (28 loc) · 1.04 KB
/
emulator_runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from multiprocessing import Process
class EmulatorRunner(Process):
def __init__(self, id, emulators, variables, queue, barrier):
super(EmulatorRunner, self).__init__()
self.id = id
self.emulators = emulators
self.variables = variables
self.queue = queue
self.barrier = barrier
def run(self):
super(EmulatorRunner, self).run()
self._run()
def _run(self):
count = 0
while True:
instruction = self.queue.get()
if instruction is None:
break
for i, (emulator, action) in enumerate(zip(self.emulators, self.variables[-1])):
new_s, reward, episode_over = emulator.next(action)
if episode_over:
self.variables[0][i] = emulator.get_initial_state()
else:
self.variables[0][i] = new_s
self.variables[1][i] = reward
self.variables[2][i] = episode_over
count += 1
self.barrier.put(True)