-
Notifications
You must be signed in to change notification settings - Fork 3k
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
AttributeError: 'thread._local' object has no attribute 'indentation' #2553
Comments
Can you give the entire error? |
Also what you were doing to trigger it. |
I cannot reproduce it here, the following stacktrace sent me my colleague:
This error occurs in Pyramid application installed within virtual environmen with the following command:
When we downgraded pip to 1.5.4 this error was gone. |
Also seeing this issue after upgrading to pip 6. I think it has to do with logging from something other than the main thread if pip has been imported in a python process. |
Would it be an idea to have get_indentation return 0 if This would do the job: def get_indentation():
return getattr(_log_state, 'indentation', 0) |
Fixes pypa#2553. When a Python script embeds pip and tries to log something from a different thread, an AttributeError is raised.
@balloob @dstufft I think this just masks the problem... The issue is that _log_state is a thread.local() object - I'm not sure why - and the indentation attribute is set in the global scope - i.e. it is only visible to the thread that first imports pip. Any other thread has a problem... @dstufft Is there a reason that it is a thread local object? |
I hit this issue in pip '9.0.1'. Here's the code snippet I used
|
Same here (pip 9.0.1). The issue seems to be that this line is not using |
So how can I fix this on the pip module? |
@zjffdu
@monty6400 You just have to modify 2 lines in |
@pradyunsg I understood that, but the lines I need to modify are zipped, so I can't modify them, is there any way I'm not aware of to modify these lines? Thanks anyway! |
@monty6400 As I said, it's likely that your use of pip is incorrect if you're running into this error.
Nope. I don't think so.
Yes, that's the modification. |
@pradyunsg |
You're importing pip and calling That said, I'm in the middle of something so, I'll let myself out of this discussion now. :) |
I saw no subprocess.run, only call (I'm using python 2.7 maybe that's the reason), anyway I saw multiprocessing and made the code run the pip installer in another window (the problem was not with the call of main, but with the call to the pip installer), and I see no problem for now. thanks for the help |
I made #4654 to address this. |
Summary (for clarity) pip does not support use in-process via its internal API, and in particular the pip code makes no guarantees that it can be used safely in the presence of threads. |
Do you know when this fix will be released? |
@dmvieira never, as the pr got closed |
@dmvieira This won't be fixed since fixing this is essentially moving a bit towards supporting people's use of an unsupported API. FWIW, we know that there'll be some sort of other bug that'll bite you even if this fix gets merged simply because [what @pfmoore stated above]. That said, if you're feeling fancy, you can patch pip's functions but then you're on you own. :) |
Ok! Better answer 😊 thx |
@pypa/pip-committers Do any of you think now reverting #2977 is a good idea? |
I think we probably shouldn't have committed it, and we should have been stricter over our "no supported API" position, but hindsight is easy, and I don't think it's worth reverting now. But it shouldn't be taken as a precedent that we'll accept further changes in support of using the internal API. |
I agree with @pfmoore |
Cool. :) |
Traceback points here https://github.com/pypa/pip/blob/develop/pip/utils/logging.py#L39
The text was updated successfully, but these errors were encountered: