-
Notifications
You must be signed in to change notification settings - Fork 361
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
Do not lock around writing to stdout, do not flush #1411
base: devel
Are you sure you want to change the base?
Conversation
a2aaf2a
to
2279033
Compare
f732423
to
401a77f
Compare
a7f8aa2
to
a6e8a45
Compare
a6e8a45
to
dc13412
Compare
def _getcallargs(sig: inspect.Signature, *args: P.args, **kwargs: P.kwargs) -> types.MappingProxyType: | ||
ba = sig.bind(*args, **kwargs) | ||
ba.apply_defaults() | ||
return types.MappingProxyType(ba.arguments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stuff is unnecessary for this PR, and if desired I can remove the last commit. Looking at things like this just drove me a little crazy:
log_only = args[5] if len(args) >= 6 else kwargs.get('log_only', False)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't safely functools.cache
the bound args this way- any non-hashable value passed to a display method would cause a runtime error. There isn't really a benefit to caching this one in real-world usage anyway, since every unique combination of args is a new cache entry, so this would basically just be a memory leak bound by the size of the cache. Several of the display methods happily accept unhashable args, and last I checked there are a number of callers that blindly pass arbitrary objects to display methods.
Caching the signature this way should be fine (though you might want to verify that inspect
isn't already doing so), since method objects are usually immutable/hashable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signature
objects are hashable, and as far as I have been able to confirm they are not cached within inspect
.
I was also skeptical of caching the _getcallargs
function, purely for the concern of how much it would cache. I'll remove that one.
Reproducer for deadlock:
|
Do not lock around writing to stdout, do not flush