Skip to content

Commit

Permalink
Revert "Use multithreading in guess_service2()"
Browse files Browse the repository at this point in the history
This reverts commit ae2b41b.
  • Loading branch information
ricardobranco777 committed Oct 10, 2023
1 parent 338911f commit 5595548
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions services/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import os
from concurrent.futures import ThreadPoolExecutor, as_completed
from contextlib import closing
from functools import cache
from typing import Any
Expand Down Expand Up @@ -89,28 +88,15 @@ def guess_service2(server: str) -> Any | None:
if os.getenv("DEBUG"):
session.hooks["response"].append(debugme)

def make_request(method: str, cls: Any, endpoint: str, status: int) -> Any | None:
url = f"https://{server}/{endpoint}"
try:
response = session.request(method, url, timeout=5)
if response.status_code == status:
return cls
except RequestException:
pass
return None

max_workers = min(10, len(endpoints["GET"]) + len(endpoints["HEAD"]))
with closing(session), ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = []
with closing(session):
for method, want in endpoints.items():
for cls, endpoint, status in want:
futures.append(
executor.submit(make_request, method, cls, endpoint, status)
)

for future in as_completed(futures):
result = future.result()
if result:
return result
url = f"https://{server}/{endpoint}"
try:
response = session.request(method, url, timeout=5)
if response.status_code == status:
return cls
except RequestException:
pass

return None

0 comments on commit 5595548

Please sign in to comment.