-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
Prevent exponential number of calls while accessing "closed" / "isatty" (#196) #198
Conversation
This does fix the problem in #196. |
@Delgan I think I understand your comment in #197 about the call traces being more complex than needed, but I don't think I follow what the problem in #196 is exactly. If we wrap the streams too many times then this fix will only be a temporary relief and not a real fix, because there will still be too many nesting calls. Won't there..? If I understand correctly the problem was not maximum recursion? It will help to understand the problem if you can provide a minimal sample code (without modifying colorama) that reproduces this and explain exactly what happens. Thanks. |
@wiggin15 You seem to have very well understood the problem. :) The following program should hang forever (make sure to run it on Windows, or add import colorama
for i in range(100):
colorama.init() You can observe how the time required to retrieve import time
import sys
from colorama import AnsiToWin32
stream = sys.stderr
while True:
stream = AnsiToWin32(stream, convert=True).stream
start = time.process_time()
stream.closed
end = time.process_time()
print(end - start) This is not a proper "nesting" issue, the issue is that fetching The maximum recursion depth can't even be reached, so there is no exception. This is the exponential number of functions calls to be made hich provokes the program to hangs when accessing Running the same code with my changes will not freeze the program but instead raises a The issue #196 appears when calling |
@wiggin15 Unfortunately, reverting 2057f03 would not help with that. The most straightforward workaround is to not wrap the same stream too many times (what's the point anyway?). |
Thanks! |
See #197 for extended discussion.