Closed ethancaballero closed 6 years ago
Found a fix in this stackoverflow response: http://stackoverflow.com/a/11283425
It's possible you can avoid this issue by not loading any of Twisted until you've already created the child processes. This would turn your usage into a single-process use case as far as Twisted is concerned (in each process, it would be initially loaded, and then that process would not go on to fork at all, so there's no question of how fork and Twisted interact anymore). This means not even importing Twisted until after you've created the child processes.
So for multiprocessing + universe, that would mean this:
import multiprocessing as mp
def worker(rank):
import gym
import universe
env = gym.make('flashgames.NeonRace-v0')
env.configure(remotes=1, client_id=rank)
observation_n = env.reset()
while True:
action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n]
observation_n, reward_n, done_n, info = env.step(action_n)
num_processes = 1
processes = []
for rank in range(num_processes):
p = mp.Process(target=worker, args=(rank,))
p.start()
processes.append(p)
for p in processes:
p.join()
^which works
You might want to add this to the "Solutions to common problems" wiki.
Expected behavior
I expected Universe env running in a multiprocessing process to respond to action steps issued in that process.
Actual behavior
When running this code the environment make and reset work, but action step has no effect (e.g NeonRace-v0 controlled car doesn't respond to actions) .
^You need to run this code on Linux. Running on Mac OS X will cause error with Twisted because OS X only uses file systems (not file descriptors) for multiprocessing.
Versions
Please include the result of running
^I'm running this in default docker instance provided by universe repo