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

Process-safe launching of minecraft instance to solve creating multiple minerl environments in parallel #352

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

juliusfrost
Copy link
Contributor

@juliusfrost juliusfrost commented Jul 13, 2020

Adds a simple thread lock to prevent multiple processes from accessing the launch script. This prevents gradle build errors when trying to create multiple minerl environments in parallel. This passes asynchronous creation in #334 with the help of #351

@minerllabs
Copy link
Collaborator

Does this require waiting for one instance to lock then launching the next?

@juliusfrost
Copy link
Contributor Author

juliusfrost commented Jul 13, 2020

@minerllabs Yes, one thread acquires the lock first, then other threads wait in a queue to acquire the lock after the first one exits. There could be a way to narrow the scope of the lock period, but so far as I see it, there isn't a good way as the logic is controlled in the Minecraft client. But in practice, I didn't see much of an issue with the locking, other than it taking a while to launch all of the environments.

@juliusfrost
Copy link
Contributor Author

I found that this solution doesn't work with certain multiprocessing techniques to parallelize the environments, such as in RLlib. So this pull might not be the best to merge yet. I'll be looking into this.

@pep8speaks
Copy link

pep8speaks commented Jul 14, 2020

Hello @juliusfrost! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 51:80: E501 line too long (84 > 79 characters)

Comment last updated at 2020-07-14 20:43:18 UTC

@juliusfrost juliusfrost changed the title Thread-safe launching of minecraft instance to solve creating multiple minerl environments in parallel Process-safe launching of minecraft instance to solve creating multiple minerl environments in parallel Jul 14, 2020
@@ -47,6 +48,8 @@

missions_dir = os.path.join(os.path.dirname(__file__), 'missions')

launch_instance_lock = FileLock(os.path.join(os.path.dirname(__file__), 'env.lock'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileLock uses a file as communication for processes to proceed in the code. When a process enters the launch instance code, FileLock creates a file env.lock in the same directory and prevents other processes from entering unless the lock is removed.

Copy link
Contributor Author

@juliusfrost juliusfrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes require adding the filelock module to requirements.txt. I've replaced the thread lock to this instead to work with multiple processes. This is a necessary change to add multiprocessing support, but parallelization improvements can be made if direct modification with Malmo is involved.

@juliusfrost
Copy link
Contributor Author

@MadcowD @minerllabs What should be done further to merge this?

@neevparikh
Copy link

Hey this would be nice to have @MadcowD @minerllabs. Can we approve this PR?

@danijar
Copy link

danijar commented Dec 3, 2021

Any update on this?

@Miffyli
Copy link
Contributor

Miffyli commented Dec 4, 2021

This seems to have been fixed in the latest version. At least this test script runs fine (but for some reason runs slow on my machine, even with a single environment. Might be my mangled environments). Parallel instances do not work on Windows, tho.

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.

6 participants