Skip to content
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

hack: retry commands to avoid throttling #208

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pyonepassword/_op_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import logging
import subprocess
from os import environ
Expand Down Expand Up @@ -51,6 +52,19 @@ def _should_log_op_errors(cls) -> bool:

@classmethod
def _run_raw(cls, argv, input=None, capture_stdout=False, ignore_error=False, env=environ):
timeout = 2
start = time.time()
while time.time() - start < timeout:
try:
return cls._run_raw_single(argv, input=input, capture_stdout=capture_stdout, ignore_error=ignore_error, env=env)
except OPCmdFailedException as _err:
# cache exception for reraising at the end of the loop
err = _err
cls.logger.warning(f"'op' command error: {err.err_output}")
raise err

@classmethod
def _run_raw_single(cls, argv, input=None, capture_stdout=False, ignore_error=False, env=environ):
stdout = subprocess.PIPE if capture_stdout else None
if input:
if isinstance(input, str):
Expand Down