Repository: biopython/biopython

Issue:
Consider including warnings on Bio.Blast.NCBIWWW qblast function if search takes longer than x minutes
### Setup

I am reporting a suggestion for Biopython version, Python version, and operating
system as follows:

**Biopython version**: 1.81
**Python version**: 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:40:32) [GCC 12.3.0]
**OS**: CPython; Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35

### Actual behaviour

Function `qblast ` from `Bio.Blast.NCBIWWW` often takes really long to complete its analysis.

### Suggested behaviour

While I completely agree with @MarkusPiotrowski response to issue #3886 on inserting a timeout, I still believe that flagging a warning if the search time becomes longer than _x_ minutes (let's say 10, for simplicity) could be a value added to the function.

### Steps to reproduce

Here is what I came up with as a possible solution:

_from [line 265](https://github.com/biopython/biopython/blob/a9dac212df80e26c75d889c6eef9a6f7614446e2/Bio/Blast/NCBIWWW.py#L265) to [line 282](https://github.com/biopython/biopython/blob/a9dac212df80e26c75d889c6eef9a6f7614446e2/Bio/Blast/NCBIWWW.py#L282) in [Bio/Blast/NCBIWWW.py](https://github.com/biopython/biopython/blob/a9dac212df80e26c75d889c6eef9a6f7614446e2/Bio/Blast/NCBIWWW.py)_
```python
start_time = time.time()
    while True:
        current = time.time()
        wait = qblast.previous + delay - current
        if wait > 0:
            time.sleep(wait)
            qblast.previous = current + wait
        else:
            qblast.previous = current
        # delay by at least 60 seconds only if running the request against the public NCBI API
        if delay < 60 and url_base == NCBI_BLAST_URL:
            # Wasn't a quick return, must wait at least a minute
            delay = 60
        elapsed = time.time() - start_time
        if elapsed>=600:
            warnings.warn("Time elapsed is larger than 10 minutes, consider re-issuing your request", BiopythonWarning)
        request = Request(url_base, message, {"User-Agent": "BiopythonClient"})
        handle = urlopen(request)
        results = handle.read().decode()
```

I hope this was useful and I wish you all the very best,
Astra



Discussion:
That seems reasonable, assuming @MarkusPiotrowski has no objection.

You should be able to make a pull request with this change via the GitHub interface in the browser (just use the edit button on https://github.com/biopython/biopython/blob/master/Bio/Blast/NCBIWWW.py and it should guide you through the process). It might need a little tweaking afterwards for style.
Perfect, I'll do it! 

Resolving patch:
diff --git a/Bio/Blast/NCBIWWW.py b/Bio/Blast/NCBIWWW.py
--- a/Bio/Blast/NCBIWWW.py
+++ b/Bio/Blast/NCBIWWW.py
@@ -263,6 +263,7 @@ def qblast(
     # will take longer thus at least 70s with delay. Therefore,
     # start with 20s delay, thereafter once a minute.
     delay = 20  # seconds
+    start_time = time.time()
     while True:
         current = time.time()
         wait = qblast.previous + delay - current
@@ -275,6 +276,13 @@ def qblast(
         if delay < 60 and url_base == NCBI_BLAST_URL:
             # Wasn't a quick return, must wait at least a minute
             delay = 60
+        elapsed = time.time() - start_time
+        # Throw a warning if search takes longer than ten minutes
+        if elapsed >= 600:
+            warnings.warn(
+                "Search is taking longer than 10 minutes, consider re-issuing it",
+                BiopythonWarning,
+            )
 
         request = Request(url_base, message, {"User-Agent": "BiopythonClient"})
         handle = urlopen(request)


Test patch: