Skip to content

Commit 9121860

Browse files
committed
Improve concurrency handling in query_all_repos by using a dedicated GitHub client for each thread
1 parent fb956e8 commit 9121860

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

get_secret_scanning_scan_history_progress.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,17 @@ def query_all_repos(
164164
file=sys.stderr,
165165
)
166166

167+
def _worker(repo: str) -> RepoResult:
168+
# Each thread gets its own GitHub client to avoid sharing
169+
# the non-thread-safe requests.Session across threads.
170+
thread_gh = GitHub(
171+
hostname=g.hostname, verify=g.session.verify
172+
)
173+
return _fetch_scan_history(thread_gh, repo)
174+
167175
with ThreadPoolExecutor(max_workers=concurrency) as executor:
168176
futures = {
169-
executor.submit(_fetch_scan_history, g, repo): repo for repo in repos
177+
executor.submit(_worker, repo): repo for repo in repos
170178
}
171179
for future in as_completed(futures):
172180
result = future.result()
@@ -182,8 +190,9 @@ def _parse_completed_date(date_str: str | None) -> datetime | None:
182190
"""Parse a completed_at date string, returning None on failure."""
183191
if not date_str or date_str == "-":
184192
return None
193+
normalized = date_str[:-1] + "+00:00" if date_str.endswith("Z") else date_str
185194
try:
186-
return datetime.fromisoformat(date_str)
195+
return datetime.fromisoformat(normalized)
187196
except (ValueError, TypeError):
188197
return None
189198

0 commit comments

Comments
 (0)