Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test case for VideoRecorder #2404

Merged
merged 2 commits into from
Sep 26, 2021
Merged

Update test case for VideoRecorder #2404

merged 2 commits into from
Sep 26, 2021

Conversation

XuehaiPan
Copy link
Contributor

Refer to #2318 for more details.

@jkterry1
Copy link
Collaborator

@XuehaiPan this fixes both of those notes right?

@XuehaiPan
Copy link
Contributor Author

This PR takes the tests for closer back for the first comment. #2318 (comment)

As commented in #2318 (comment) (the second comment) and #2318 (comment), we could remove all closers in gym entirely (not only for VideoRecoder, but also for Monitor, etc.), and call close() in the __del__() method.

@vwxyzjn
Copy link
Contributor

vwxyzjn commented Sep 12, 2021

I like the idea of having "close() in the __del__() method", which seems like a much cleaner solution than a customized Closer. If we move forward with this idea, would it make the test cases cleaner?

@XuehaiPan
Copy link
Contributor Author

XuehaiPan commented Sep 13, 2021

I like the idea of having "close() in the __del__() method", which seems like a much cleaner solution than a customized Closer. If we move forward with this idea, would it make the test cases cleaner?

Definitely. This will make both the implementation and the tests simpler for classes with a close() method (e.g., Env, Monitor, VideoRecorder, etc.). But we should be careful if we add this behavior to the fundamental base classes (Env, Wrapper, etc.).

First, If we want to test the side effect (e.g. create a video file) for a close() method that called implicitly by __del__() (the test_autoclose in this PR), we should do explicit garbage collection and wait for a few seconds (as we cannot know when will the Python interpreter do a garbage cleaning):

import time
import gc

rec_path, proc, num_registered = record()

gc.collect()  # do explicit garbage collection for test
time.sleep(5)  # wait for subprocess exiting

assert proc.poll() is not None  # subprocess is terminated

Second, for some classes, we should and an attribute _closed to instances to avoid duplicate closeing.

def duplicate_close():
    env = MyEnv()
    env.close()  # explicit closing

    # After the function exiting
    # `__del__()` will call `close()` again

duplicate_close()

@jkterry1
Copy link
Collaborator

@XuehaiPan can you please make the remaining requested changes (by costa and the second comment) so this can be merged?

@XuehaiPan
Copy link
Contributor Author

I think the first commit (a888dfa) is enough to reply to both of the comments. I have removed closer for VideoRecorder in the new commit (78e1edb) to simplify the tests. (#2404 (comment) and #2404 (comment))

@jkterry1 jkterry1 merged commit 000a2a0 into openai:master Sep 26, 2021
@XuehaiPan XuehaiPan deleted the videorecorder-test branch October 1, 2021 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants