Skip to content

Commit d598b02

Browse files
Add exponential backoff
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 71458a8 commit d598b02

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/openfermion/chem/pubchem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ def geometry_from_pubchem(name: str, structure: str = None):
3838

3939
def get_compounds_with_retries(name, record_type):
4040
max_retries = 3
41-
delay = 2
41+
initial_delay = 1
4242
for attempt in range(max_retries):
4343
try:
4444
return pubchempy.get_compounds(name, 'name', record_type=record_type)
4545
except (pubchempy.PubChemHTTPError, urllib.error.URLError):
4646
if attempt == max_retries - 1:
4747
raise
48+
delay = initial_delay * (2 ** attempt)
4849
time.sleep(delay)
4950

5051
if structure in ['2d', '3d']:

0 commit comments

Comments
 (0)