<div dir="ltr">I ran in to a similar problem downloading multiple FASTA files from NCBI where it would get 'hung up' on large sequences.  I found a function on StackOverflow that worked well. It's super simple, effective, and should work with your search with minor tweeking.  It's currently set to timeout after 10 seconds.<div><br></div><div>  Damian</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 26, 2017 at 6:24 AM, Peter Cock <span dir="ltr"><<a href="mailto:p.j.a.cock@googlemail.com" target="_blank">p.j.a.cock@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">That does help, thank you.<br>
<br>
First of all that tells me you are using Windows and your Python is<br>
from Anaconda (probably not important here).<br>
<br>
Now, I had been guessing the code was getting stuck while actually<br>
connecting to the NCBI and waiting an update - which is where that<br>
socket timeout would come into play.<br>
<br>
I see now the problem is when Biopython checks for an update,<br>
waits for a bit, checks for an update, waits for a bit, ... and never<br>
gives up:<br>
<br>
<a href="https://github.com/biopython/biopython/blob/biopython-170/Bio/Blast/NCBIWWW.py#L164" rel="noreferrer" target="_blank">https://github.com/biopython/<wbr>biopython/blob/biopython-170/<wbr>Bio/Blast/NCBIWWW.py#L164</a><br>
<br>
The code increases the wait interval to 120s (two minutes), but<br>
currently has no (optional) maximum total waiting time. Adding<br>
this as an option seems sensible (e.g. a maximum total waiting<br>
time of say 5 or 10 mins).<br>
<br>
Also, it would be good to check if the NCBI is returning some<br>
clue or error message which our code does not understand...<br>
<br>
>From your initial description is sounds like you have not found<br>
any single example which fails - so this is going to be hard to<br>
test.<br>
<br>
Peter<br>
<br>
On Wed, Jul 26, 2017 at 3:04 PM, Pejvak Moghimi<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:pejvak.moghimi@york.ac.uk">pejvak.moghimi@york.ac.uk</a>> wrote:<br>
> Hi Peter,<br>
><br>
> Here it is:<br>
><br>
> Traceback (most recent call last):<br>
><br>
>   File "<ipython-input-107-<wbr>561cd74d2097>", line 1, in <module><br>
>     runfile('D:/Dropbox/Pejvak<br>
> Moghimi/DMT_project/blast_for_<wbr>clav_seqs/blastScript(altered)<wbr>.py',<br>
> wdir='D:/Dropbox/Pejvak Moghimi/DMT_project/blast_for_<wbr>clav_seqs')<br>
><br>
>   File<br>
> "C:\Users\pezhv\Anaconda3\lib\<wbr>site-packages\spyder\utils\<wbr>site\sitecustomize.py",<br>
> line 880, in runfile<br>
>     execfile(filename, namespace)<br>
><br>
>   File<br>
> "C:\Users\pezhv\Anaconda3\lib\<wbr>site-packages\spyder\utils\<wbr>site\sitecustomize.py",<br>
> line 102, in execfile<br>
>     exec(compile(f.read(), filename, 'exec'), namespace)<br>
><br>
>   File "D:/Dropbox/Pejvak<br>
> Moghimi/DMT_project/blast_for_<wbr>clav_seqs/blastScript(altered)<wbr>.py", line 116,<br>
> in <module><br>
>     result_handle = NCBIWWW.qblast("blastp", "nr", sequence,<br>
> hitlist_size=500, entrez_query = orgn_specified)<br>
><br>
>   File "C:\Users\pezhv\Anaconda3\lib\<wbr>site-packages\Bio\Blast\<wbr>NCBIWWW.py",<br>
> line 164, in qblast<br>
>     time.sleep(wait)<br>
><br>
><br>
> Cheers,<br>
> Pej.<br>
><br>
><br>
> On 26 July 2017 at 14:57, Peter Cock <<a href="mailto:p.j.a.cock@googlemail.com">p.j.a.cock@googlemail.com</a>> wrote:<br>
>><br>
>> Hi Pej.<br>
>><br>
>> Hmm. Maybe setting the timeout is not going to solve your<br>
>> problem. I was hoping that would be a neat solution.<br>
>><br>
>> Can you show us the stack trace when you had to stop a job<br>
>> please?<br>
>><br>
>> I assume you are using control+c to do this, in which case<br>
>> Python ought to stop with the exception KeyboardInterrupt.<br>
>> What I am interested in here is where in the code Python<br>
>> is getting stuck. That would be a good clue.<br>
>><br>
>> Peter<br>
>><br>
>> On Wed, Jul 26, 2017 at 2:47 PM, Pejvak Moghimi<br>
>> <<a href="mailto:pejvak.moghimi@york.ac.uk">pejvak.moghimi@york.ac.uk</a>> wrote:<br>
>> > Hi Peter,<br>
>> ><br>
>> > That solution, so far, does not seem to have worked nor with 10 neither<br>
>> > with<br>
>> > 30 second options.<br>
>> ><br>
>> > Cheers,<br>
>> > Pej.<br>
>> ><br>
>> > On 26 July 2017 at 13:29, Peter Cock <<a href="mailto:p.j.a.cock@googlemail.com">p.j.a.cock@googlemail.com</a>> wrote:<br>
>> >><br>
>> >> I am hoping that putting this near the start of your script will<br>
>> >> apply the default timeout to all your BLAST calls (or other<br>
>> >> network calls, e.g. NCBI Entrez):<br>
>> >><br>
>> >> import socket<br>
>> >> socket.setdefaulttimeout(30)  # timeout in seconds<br>
>> >><br>
>> >> Peter<br>
><br>
><br>
</div></div><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Biopython mailing list  -  <a href="mailto:Biopython@mailman.open-bio.org">Biopython@mailman.open-bio.org</a><br>
<a href="http://mailman.open-bio.org/mailman/listinfo/biopython" rel="noreferrer" target="_blank">http://mailman.open-bio.org/<wbr>mailman/listinfo/biopython</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif" size="2">Damian Menning, Ph.D.</font></div><div><font face="arial, helvetica, sans-serif" size="2"><br></font></div><div><font face="arial, helvetica, sans-serif" size="2">"There are two types of academics. Those who use the Oxford comma, those who don't and those who should."</font></div><div><font face="arial, helvetica, sans-serif" size="2"><br></font></div><div><font face="arial, helvetica, sans-serif" size="2">Standard comma - You know Bob, Sue and Greg? They came to my house.</font></div><div><font face="arial, helvetica, sans-serif" size="2">Oxford comma - </font><span style="font-family:arial,helvetica,sans-serif;font-size:small">You know Bob, Sue, and Greg? They came to my house.</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:small">Walken Comma - </span><span style="font-family:arial,helvetica,sans-serif;font-size:small">You know, Bob, Sue, and Greg? They came, to my house.</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:small">Shatner comma - </span><span style="font-family:arial,helvetica,sans-serif;font-size:small">You, know, Bob, Sue, and Greg? They, came, to my house.</span></div></div></div></div></div></div></div></div></div></div></div></div>
</div>