Farama-Foundation / Farama-Foundation/Arcade-Learning-Environment

Segfaulting Unrelated Threads?

Open
#341 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
477
Avg merge
11h 11m
Merged PRs (30d)
3

Description

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!

Contributor guide

Open the contributing guide

Research direction

Run the minimal reproducer with MsPacman-v4 and compare it with CartPole-v0, using Python 3.7 and faulthandler as shown. Review the Atari-related behavior and the referenced openai/atari-py#52 discussion; done means nested threads no longer cause a segmentation fault after gym.make has run, with a regression test covering the reproducer.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.