Games-and-Simulations / sc-docker

Multi-platform Version of StarCraft: Brood War in a Docker Container, ready to use for bot play simulations.
MIT License
231 stars 40 forks source link

Crash on downloading maps #7

Closed kant2002 closed 6 years ago

kant2002 commented 6 years ago

I run example from the README.md - scbw --bots "krasi0" "CherryPi" --show_all and have following output

INFO checking docker version
INFO checking docker can run
INFO checking docker has network sc_net
INFO downloading maps from SSCAI
Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\scbw\__main__.py", line 132, in main
    check_map_exists(args.map_dir + "/" + args.map)
  File "c:\program files\python36\lib\site-packages\scbw\map.py", line 13, in check_map_exists
    raise Exception(f"Map {map_file} could not be found")
Exception: Map c:\program files\python36\lib\site-packages\scbw/maps/sscai/(2)Benzene.scx could not be found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\scbw\utils.py", line 37, in download_extract_zip
    download_file(url, filename)
  File "c:\program files\python36\lib\site-packages\scbw\utils.py", line 49, in download_file
    opener.retrieve(url, as_file)
  File "c:\program files\python36\lib\urllib\request.py", line 1819, in retrieve
    block = fp.read(bs)
  File "c:\program files\python36\lib\tempfile.py", line 483, in func_wrapper
    return func(*args, **kwargs)
ValueError: read of closed file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\program files\Python36\scripts\scbw.exe\__main__.py", line 9, in <module>
  File "c:\program files\python36\lib\site-packages\scbw\__main__.py", line 135, in main
    download_sscait_maps(args.map_dir)
  File "c:\program files\python36\lib\site-packages\scbw\map.py", line 18, in download_sscait_maps
    download_extract_zip("http://sscaitournament.com/files/sscai_map_pack.zip", map_dir)
  File "c:\program files\python36\lib\site-packages\scbw\utils.py", line 42, in download_extract_zip
    os.remove(filename)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\USR\\AppData\\Local\\Temp\\tmp1_a_128q'

First is what seems to be some race condition here, and why maps should be downloaded to scbw folder? Maybe somewhere in the LOCALAPPDATA is more sensible default on Windows ?

kant2002 commented 6 years ago

I actually has crash on Mac also

INFO checking docker version
INFO checking docker can run
INFO checking docker has network sc_net
INFO creating docker local net sc_net
INFO downloading maps from SSCAI
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scbw/__main__.py", line 132, in main
    check_map_exists(args.map_dir + "/" + args.map)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scbw/map.py", line 13, in check_map_exists
    raise Exception(f"Map {map_file} could not be found")
Exception: Map /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scbw/maps/sscai/(2)Benzene.scx could not be found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/bin/scbw", line 11, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scbw/__main__.py", line 135, in main
    download_sscait_maps(args.map_dir)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scbw/map.py", line 18, in download_sscait_maps
    download_extract_zip("http://sscaitournament.com/files/sscai_map_pack.zip", map_dir)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scbw/utils.py", line 37, in download_extract_zip
    download_file(url, filename)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scbw/utils.py", line 49, in download_file
    opener.retrieve(url, as_file)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1819, in retrieve
    block = fp.read(bs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tempfile.py", line 483, in func_wrapper
    return func(*args, **kwargs)
ValueError: read of closed file

Will try to look at it later

michalsustr commented 6 years ago

Okay, I think there are 2 things going on here:

1) there is http redirect when you download the file, and the downloader doesn't follow that -- on my local network it works, that's why I didn't encouter it here. https://stackoverflow.com/a/11531981 -- instead of 403 there is some 30x http response code 2) Writing files can be problematic because of permissions -- maybe it would be better to use something like ~/.scbw folder and the windows equivalent would be LOCALAPPDATA

michalsustr commented 6 years ago

@kant2002 Can you test PR #9 please?

michalsustr commented 6 years ago

Actually, never mind. The problem was in missing os.close https://www.logilab.org/blogentry/17873

Try master?

(you should reinstall scbw package)

kant2002 commented 6 years ago

Thanks, I manage to run it when update scbw from master