<div dir="ltr"><span style="font-size:12.8px">I thought about adding a timeout parameter to qblast too, and to me it seems like the most straight forward solution.</span><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 26 July 2017 at 16:58, Nabeel Ahmed <span dir="ltr"><<a href="mailto:chaudhrynabeelahmed@gmail.com" target="_blank">chaudhrynabeelahmed@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class=""><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="m_6625612659983034378gmail-im" style="font-size:12.8px">> Suggestion 3: Make direct API calls using 'requests' package.<br></span><span class="m_6625612659983034378gmail-im" style="font-size:12.8px">> In case the API calls are simple (you can easily do so) use request to make<br></span><span class="m_6625612659983034378gmail-im" style="font-size:12.8px">> a call, with timeout flag, once the HTTP request will timeout it'll raise<br></span><span class="m_6625612659983034378gmail-im" style="font-size:12.8px">> Timeout exception, which you can catch and in that block make the second<br></span><span class="m_6625612659983034378gmail-im" style="font-size:12.8px">> call (which as per you, works perfectly fine)</span> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="m_6625612659983034378gmail-im" style="font-size:12.8px"><br></span><span style="font-size:12.8px">This is essentially the idea I was initially suggesting, but the problem<br></span><span style="font-size:12.8px">isn't actually in the online request (currently done by urlopen).</span><br style="font-size:12.8px"><span style="font-size:12.8px">With the NCBI BLAST you typically submit a query, wait, check for<br></span><span style="font-size:12.8px">progress, wait (repeat), and then download the results. This loop in<br></span><span style="font-size:12.8px">Biopython has no timeout - it relies on the NCBI returning results<br></span><span style="font-size:12.8px">eventually - or giving an error.</span></blockquote><div><br></div></span><div> Yh, what you're saying is, the response in <b>qblast </b>call depends on lot of factors, and varies from a job to job i.e. </div><div>data size, NCBI servers' response time, etc.</div><div>Given this, there isn't any point in having a timeout param for this call.</div><div><br></div><div>But, in case in case, it's required, can patch <b>qblast</b> with a new param '<b>timeout</b>', and I have looked into the source code (for Python 2.x) it's <a href="http://biopython.org/DIST/docs/api/Bio._py3k-pysrc.html" target="_blank">using <b>urlopen</b> from urllib2 package</a> (line 172)</div><div>This <a href="https://docs.python.org/2/library/urllib2.html#urllib2.urlopen" target="_blank"><b>urlopen </b>allows <b>timeout</b></a> as an argument.</div><div>Can have an optional param - timeout=0 for qblast, and pass it to urlopen:</div><div><br></div>handle = _urlopen(request, timeout=timeout)  - <a href="http://biopython.org/DIST/docs/api/Bio.Blast.NCBIWWW-pysrc.html" target="_blank">Line 132 and 176</a><div><div class="h5"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 26, 2017 at 8:18 PM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="m_6625612659983034378gmail-">On Wed, Jul 26, 2017 at 1:37 PM, Nabeel Ahmed<br>
<<a href="mailto:chaudhrynabeelahmed@gmail.com" target="_blank">chaudhrynabeelahmed@gmail.com</a><wbr>> wrote:<br>
> Hi,<br>
><br>
> Disclaimer: I haven't used ncbiWWW module.<br>
><br>
> Suggestion 1: if you're using a *NIX system. Can make use of Signals. Wrap<br>
> your call with the signal. Define the signal handler:<br>
<br>
</span>I think that approach would work here - thanks!<br>
<span class="m_6625612659983034378gmail-"><br>
> Suggestion 2: using Multiprocessing or multithreading - for it, kindly share<br>
> your script/snippet.<br>
<br>
</span>Again that would likely work, but will be more complicated.<br>
<span class="m_6625612659983034378gmail-"><br>
> Suggestion 3: Make direct API calls using 'requests' package.<br>
> In case the API calls are simple (you can easily do so) use request to make<br>
> a call, with timeout flag, once the HTTP request will timeout it'll raise<br>
> Timeout exception, which you can catch and in that block make the second<br>
> call (which as per you, works perfectly fine):<br>
<br>
</span>This is essentially the idea I was initially suggesting, but the problem<br>
isn't actually in the online request (currently done by urlopen).<br>
<br>
With the NCBI BLAST you typically submit a query, wait, check for<br>
progress, wait (repeat), and then download the results. This loop in<br>
Biopython has no timeout - it relies on the NCBI returning results<br>
eventually - or giving an error.<br>
<span class="m_6625612659983034378gmail-HOEnZb"><font color="#888888"><br>
Peter<br>
</font></span></blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div>