Files
Gymnasium/gym/utils/tests/test_atexit.py
Greg Brockman 8376580c85 Improve closer implementation and docstrings (#126)
* Improve auto close implementation

- Register all envs at initialization time, not just ones created via make
- Simplify names and add more documentation on interface
- Move closer instances into the relevant modules

review-requested: @jietang

* Close environments in the tests

This isn't strictly needed, but means there are fewer Doom
subprocesses hanging around while the tests run.

* Use 4 space indent in comment

* Improve docstrings in core

* Don't pass through args to __new__

The __init__ method gets called once __new__ returns,
so these arguments are either ignored (Python 2) or
result in an error (Python 3). The __init__ method
automatically gets called with the correct arguments.

* Fixup comments
2016-05-27 12:16:35 -07:00

22 lines
491 B
Python

from gym.utils.closer import Closer
class Closeable(object):
close_called = False
def close(self):
self.close_called = True
def test_register_unregister():
registry = Closer(atexit_register=False)
c1 = Closeable()
c2 = Closeable()
assert not c1.close_called
assert not c2.close_called
registry.register(c1)
id2 = registry.register(c2)
registry.unregister(id2)
registry.close()
assert c1.close_called
assert not c2.close_called