-
Notifications
You must be signed in to change notification settings - Fork 21
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
add support for Process Credentials Provider #194
base: master
Are you sure you want to change the base?
Conversation
stdout=asyncio.subprocess.PIPE, | ||
stderr=asyncio.subprocess.PIPE, | ||
stdin=asyncio.subprocess.PIPE, | ||
) | ||
stdout, stderr = await process.communicate(b"") |
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 would block if the subprocess produces too much data.
Arguably there should be a default timeout too, although, perhaps in this particular library, the caller has a timeout and will cancel fetch_metadata
.
A simple fix could look smth like:
try:
stdout, stderr = await asyncio.wait_for(
process.communicate(b""), timeout=30
)
except asyncio.TimeoutError:
process.kill()
await process.wait()
raise ProcessCredentialsError("Subprocess timed out", None, b"", b"")
I dunno if it's worth it in practice.
) | ||
try: | ||
data = json.loads(stdout) | ||
except json.JSONDecodeError: |
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.
Hmmm I can't recall if they fixed this or not. Back in the day, except ValueError
was better, because JSONDecodeError inherits from it, and in some special cases loads could raise a plain ValueError?
def try_decode(data: bytes) -> str: | ||
try: | ||
return data.decode() | ||
except: |
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.
except: | |
except Exception: |
unless the intention is to swallow e.g. SystemExit if it happens at just the right time.
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.
It would be great to add some super-simple snippet about how to use this in real life.
Adds support for Process Credentials Provider