minerl icon indicating copy to clipboard operation
minerl copied to clipboard

VSCode debugger/process_watcher issue when running quick start code

Open seeseeatre opened this issue 4 years ago • 6 comments

I installed minerl in a fresh anaconda environment. The environment can start and operate when I run it, but not when I'm using a debugger. I'm on a Windows 10 PC.

minerl version: 0.4.2.1 Python version: 3.6.13 VSCode version:1.60.2 java version "1.8.0_301" Java(TM) SE Runtime Environment (build 1.8.0_301-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)

my code:

import gym, minerl

gym.logger.set_level(40)

def main():
    env = gym.make('MineRLNavigateDense-v0')
    obs  = env.reset()
    done = False
    net_reward = 0
    while not done:
        action = env.action_space.noop()
        action['camera'] = [0, 0.03*obs["compass"]["angle"]]
        action['back'] = 0
        action['forward'] = 1
        action['jump'] = 1
        action['attack'] = 1
        obs, reward, done, info = env.step(
            action)
        net_reward += reward
        print("Total reward: ", net_reward)
if __name__ == '__main__':
    main()

Error Log:

C:\Users\Han\AppData\Roaming\Python\Python36\site-packages\gym\logger.py:34: UserWarning: WARN: Box bound precision lowered by casting to float32
  warnings.warn(colorize("%s: %s" % ("WARN", msg % args), "yellow"))
C:\Users\Han\AppData\Roaming\Python\Python36\site-packages\gym\logger.py:34: UserWarning: WARN: Box bound precision lowered by casting to float32
  File "c:\Users\Han\.vscode\extensions\ms-python.python-2021.9.1246542782\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd.py", line 3331, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "c:\Users\Han\.vscode\extensions\ms-python.python-2021.9.1246542782\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd.py", line 2398, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "c:\Users\Han\.vscode\extensions\ms-python.python-2021.9.1246542782\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd.py", line 2422, in _exec
    runpy._run_module_as_main(module_name, alter_argv=False)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\site-packages\minerl\utils\process_watcher.py", line 175, in <module>
    daemonize(os.path.join(os_cur_dir, MINERL_WATCHERS_DIR, watcher_name + '.pid'))
  File "C:\Users\Han\AppData\Roaming\Python\Python36\site-packages\daemoniker\_daemonize_windows.py", line 453, in _daemonize1     
    'Daemon creation worker exited prematurely.'
RuntimeError: Daemon creation worker exited prematurely.
Traceback (most recent call last):
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\Han\.vscode\extensions\ms-python.python-2021.9.1246542782\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\Users\Han\.vscode\extensions\ms-python.python-2021.9.1246542782\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
    run()
  File "c:\Users\Han\.vscode\extensions\ms-python.python-2021.9.1246542782\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\Users\Han\Desktop\PhD Work Space\Miner\Miner.py", line 39, in <module>
    main()
  File "d:\Users\Han\Desktop\PhD Work Space\Miner\Miner.py", line 19, in main
    obs  = env.reset()
  File "C:\Users\Han\AppData\Roaming\Python\Python36\site-packages\gym\wrappers\time_limit.py", line 27, in reset
    return self.env.reset(**kwargs)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\site-packages\minerl\env\_singleagent.py", line 22, in reset     
    multi_obs = super().reset()
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\site-packages\minerl\env\_multiagent.py", line 455, in reset     
    self._setup_instances()
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\site-packages\minerl\env\_multiagent.py", line 556, in _setup_instances
    self.instances.extend([f.result() for f in instance_futures])
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\site-packages\minerl\env\_multiagent.py", line 556, in <listcomp>    self.instances.extend([f.result() for f in instance_futures])
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\concurrent\futures\_base.py", line 425, in result
    return self.__get_result()
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\concurrent\futures\thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\site-packages\minerl\env\_multiagent.py", line 807, in _get_new_instance
    instance.launch(replaceable=self._is_fault_tolerant)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\site-packages\minerl\env\malmo.py", line 502, in launch
    parent_pid, self.minecraft_process.pid, self.instance_dir)
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\site-packages\minerl\utils\process_watcher.py", line 54, in launch
    '--{}'.format(CHILD_DIR_ARG)] + list(temp_dirs))
  File "D:\users\han\program\visualstudio\shared\anaconda3_64\lib\subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['D:\\Users\\Han\\Program\\VisualStudio\\Shared\\Anaconda3_64\\envs\\Miner\\python.exe', '-m', 'minerl.utils.process_watcher', '15088', '9972', '--child-dirs', 'C:\\Users\\Han\\AppData\\Local\\Temp\\tmp4y2wtjzk']' returned non-zero exit status 1.

seeseeatre avatar Oct 08 '21 10:10 seeseeatre

Hmm I hazard a guess the error stems from the process handling on Windows (which can cause trouble with regular MineRL runs too, see here). Try enabling logging as done in the documentation with to get full logs from Minecraft, too, to see if it gives more insight why things failed:

import logging
logging.basicConfig(level=logging.DEBUG)

Apart from this I have no ideas to give, unfortunately :(

Miffyli avatar Oct 08 '21 13:10 Miffyli

Hmm I hazard a guess the error stems from the process handling on Windows (which can cause trouble with regular MineRL runs too, see here). Try enabling logging as done in the documentation with to get full logs from Minecraft, too, to see if it gives more insight why things failed:

import logging
logging.basicConfig(level=logging.DEBUG)

Apart from this I have no ideas to give, unfortunately :(

Thank you for the reply, I have tried to use the debug logging before I posted here, there's no new information from the logger. I suspect this has to do with the warning:

RuntimeWarning: 'minerl.utils.process_watcher' found in sys.modules after import of package 'minerl.utils', but prior to execution of 'minerl.utils.process_watcher'; this may result in unpredictable behaviour

Would downgrade minerl help? or maybe bypass the process_watcher?

seeseeatre avatar Oct 08 '21 16:10 seeseeatre

That warning happens in normal runs as well, but yes, it could be related this.

You could try installing 0.3.7, which is the most stable version before major updates recently. Fixing that error needs tracking down how imports are done and adjusting the ordering.

Miffyli avatar Oct 08 '21 18:10 Miffyli

Installing the older version didn't help, I manage to get it working by disabling the process_watcher in env/malmo.py L498-502. Is there any unforeseeable consequences for doing this?

seeseeatre avatar Oct 12 '21 10:10 seeseeatre

Installing the older version didn't help, I manage to get it working by disabling the process_watcher in env/malmo.py L498-502. Is there any unforeseeable consequences for doing this?

AFAIK that is used to make sure Minecraft instance is running and also handles closing it, so after debugging you might have an extra minecraft running in the background (or, if Minecraft crashes, it won't be rebooted).

Miffyli avatar Oct 12 '21 10:10 Miffyli

Installing the older version didn't help, I manage to get it working by disabling the process_watcher in env/malmo.py L498-502. Is there any unforeseeable consequences for doing this?

AFAIK that is used to make sure Minecraft instance is running and also handles closing it, so after debugging you might have an extra minecraft running in the background (or, if Minecraft crashes, it won't be rebooted).

Ok, I can live with this, I think, thank you!

seeseeatre avatar Oct 12 '21 11:10 seeseeatre