Farama-Foundation / Arcade-Learning-Environment

The Arcade Learning Environment (ALE) -- a platform for AI research.
https://ale.farama.org/
GNU General Public License v2.0
2.17k stars 423 forks source link

Segfaulting Unrelated Threads? #341

Open mharradon opened 4 years ago

mharradon commented 4 years ago

I've found what I believe to be quite the mysterious (and painful) bug.

A minimal reproducing example:

from threading import Thread
import faulthandler

import gym

faulthandler.enable()

def make_t2():
    print(1)

def make_t1():
    t = Thread(target=make_t2)
    t.start()

env = gym.make('MsPacman-v4')
#env = gym.make('CartPole-v0')

t = Thread(target=make_t1)
t.start()

I believe it's related to this issue: openai/atari-py#52

Essentially, it appears that nesting of threads segfault if and only if gym.make has occurred. If you comment out that line the error goes away.

This issue appeared sometime since gym release 0.15.3 . The older versions don't seem to have this problem.

If I use faulthandler I can get:

 $ python error_demo.py
1
Fatal Python error: Segmentation fault

Thread 0x00007f6b01327700 (most recent call first):
  File "/root/anaconda3/lib/python3.7/threading.py", line 989 in _stop
  File "/root/anaconda3/lib/python3.7/threading.py", line 1282 in _shutdown
[1]    83051 segmentation fault (core dumped)  python error_demo.py

So, at least as I understand, it is not even gym code that is segfaulting - rather it is somehow indirectly causing other code to segfault. I was suggested to post here from the gym repo, as this only occurs with Atari environments.

I'm using Python3.7.

Thanks!

JesseFarebro commented 4 years ago

Hi,

Can you give me more details about your setup? I ran your example using Python 3.7.1 on macOS and it doesn't segfault. Neither does the other issue you linked above.

mharradon commented 4 years ago

The issue occurs on 3.7.3 in a Docker container. I'll try to provide a container that reproduces it. I see it doesn't occur on my Mac with 3.7.3, though both are Anaconda distributions.