-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
pipenv install shows a ResourceWarning if installing fails #2320
Comments
Contributions are welcomed! |
@Julian the inference you're making is mostly right, but that resource is created out of necessity... one interesting point is that I backported We can't handle this with a context manager because the resource is actually passed around through several function calls and then ultimately to a subprocess to handle resolution. You're actually hitting a (fixed, I believe) bug in the resolver stack where the resolver sometimes calls |
@techalchemy you can still explicitly clean up the resource though, by using ExitStack, and doing the function calls and subprocess firing within the ExitStack. (And this isn't strictly PyPy related, it's the same as if you were say opening files without using with, where yeah on CPython it doesn't show noticeable negative effects but is "frowned upon" stylistically anyhow). I'll check on master though. |
If you decide to work on this, remember |
@Julian but I am telling you that we do explicitly clean up the resource. Not all of the things you described apply here -- we spawn a bunch of subprocesses which own their own process groups and they all write concurrently to the same |
At least not that I am aware of, but if you know of a way to handle this I would certainly be interested. I'd say to look at the exact circumstances to make sure it applies before assuming it does though, I have spent a bunch of time tracking down these types of issues due to maintaining cross platform compatibility with windows. |
The warning only happens if this was in fact not cleaned up, I looked at the code afterwards to confirm. It's being explicitly cleaned up, but not in a context manager, so an error (like the one that's happening to me here which is #2321) means that E.g., on this branch: https://github.com/pypa/pipenv/blob/master/pipenv/core.py#L1294-L1313 if an exception is thrown anywhere above the The way to fix is to make everything from 1294 to 1376 be inside a with block (regardless of other functions being called or subprocesses using the same resource) [but since you only conditionally create the tempdir, you'd need I'm not sure I'll get a chance to actually implement a fix myself, but yes I'm sure it'd be easier to explain if I did that :P. Will see what I can do. Also I'm not concentrating hard enough and out of all the issues this one is definitely the least important :P, so probably not worth discussing too much if I'm not being clear (or if I'm straight up wrong). |
That's actually super clear, I didn't spend a lot of time on this because it's handled implicitly (I considered disabling the warning since the |
@ncoghlan I'd love to get your take on this -- at a high level, does a direct |
Note that the cleanup isn't actually conditional on whether or not the function had to create its own So even though this is definitely a use case that
Alternatively, if we can rely on the passed in
|
edit I wrote a new issue instead since it seems to be a separate issue: #3054 This just happened for us and we are not sure how to work around this. Any workarounds available?
|
Ok this is actually becoming a problem, time to find a solution! |
(This is obviously minor, since the process is likely to exit anyhow when this happens, but filing for posterity)
My
pipenv install
is failing (for reasons I can't decipher yet, so ignore the traceback), but during the failure it looks like there's also aResourceWarning
being shownwhich appears to be because
pipenv.core.do_init
creates aTemporaryDirectory
without using a context manager orcontextlib.ExitStack
.The text was updated successfully, but these errors were encountered: