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

Invalid handle with SpockBuilder.save #296

Closed
kevindckr opened this issue Aug 3, 2023 · 1 comment · Fixed by #297
Closed

Invalid handle with SpockBuilder.save #296

kevindckr opened this issue Aug 3, 2023 · 1 comment · Fixed by #297

Comments

@kevindckr
Copy link

kevindckr commented Aug 3, 2023

I have started a simple tutorial for my use case and exploring what spock offers.

from typing import List

from spock import spock, SpockBuilder, SavePath


@spock
class ConfigPath:
    """
    Configuration definition for handling of all paths in project.

    Attributes:
        save_path: where the loaded configuation file is saved
        data_dir: the main data directory
        output_dir: the main output directory
        config_dir: the main configs directory
    """
    save_path: SavePath
    data_dir: str
    output_dir: str
    config_dir: str


if __name__ == "__main__":
    # config = SpockBuilder(ConfigPath, desc="Example configuration for paths").generate()
    # print(config)

    config = SpockBuilder(ConfigPath, desc="Example configuration for paths").save(file_extension='.json').generate()
    print(config)

The corresponding configuration file I have create is the following

{
  "save_path": "C:\\example_project\\configs",
  "data_dir": "C:\\",
  "output_dir": "C:\\",
  "config_dir": "C:\\"
}

When ran with the command python <...>\config_path.py --config paths.json I receive the following exception:

Exception ignored in: <function Popen.__del__ at 0x00000258854A5550>
Traceback (most recent call last):
  File "C:\Users\kdecker\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 949, in __del__
    self._internal_poll(_deadstate=_maxsize)
  File "C:\Users\kdecker\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1348, in _internal_poll
    if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] The handle is invalid

Though this does result in, from what I can tell, a correctly saved .toml file. It contains a header with various info about the machine, python, and git state, the [ConfigPath] parameters themselves, and a footer with the various python libraries in my environment.

This issue does not happen when not calling .save, I load the configuration file into a namespace and print it. This is all under Windows 10 system. Using spock-config 3.0.2.

@ncilfone
Copy link
Contributor

ncilfone commented Aug 3, 2023

Hi!

Thanks for all the info. I've never tested on windows only osx and linux based systems (which is noted in the installation docs somewhere but it's def not front and center enough). So I guess thanks for being a beta tester!

My first guess is that the error is occurring when spock tries to get the git info of the directory you are working out of to append to the serialized configuration file. It uses a subprocess to call out to git see here:

head_result = subprocess.run(

So it looks like something is going wonky with exiting/killing the subprocess cleanly (as indicated by the __del__ traceback)

Short term band-aid - you can set the flag within the save call to turn off writing the extra_info to the configuration file (https://fidelity.github.io/spock/reference/builder#save). e.g.

SpockBuilder(SpockClass).save(extra_info=False).generate()

This is just extra info that isn't critical to serialization of the actual spock config so everything should still work 100% normally.

I'll try and see if I can figure out what the problem is with window not existing the subprocess correctly.

Nick

ncilfone added a commit to ncilfone/spock that referenced this issue Aug 3, 2023
… to windows system needing stdin even as a null device. Other fix seems like it could be leaky resources from GitPython for long running processes. Make sure to call close() to help prevent resource leak. Also bump all the github actions ubuntu verion to 20.04 since 18.04 got deprecated
@ncilfone ncilfone mentioned this issue Aug 3, 2023
6 tasks
@ncilfone ncilfone mentioned this issue Nov 3, 2023
6 tasks
mmalouane added a commit that referenced this issue Nov 3, 2023
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 a pull request may close this issue.

2 participants