[Biopython] help with ncbiWWW

Peter Cock p.j.a.cock at googlemail.com
Wed Jul 26 12:29:15 UTC 2017


I am hoping that putting this near the start of your script will
apply the default timeout to all your BLAST calls (or other
network calls, e.g. NCBI Entrez):

import socket
socket.setdefaulttimeout(30)  # timeout in seconds

Peter

On Wed, Jul 26, 2017 at 1:26 PM, Pejvak Moghimi
<pejvak.moghimi at york.ac.uk> wrote:
> Hi Peter,
>
> Thank you. I will give it a go.
>
> Can I use this on my own script to achieve what I want, or is it strictly
> useful for altering the qblast script?
>
> Cheers,
> Pej.
>
> On 26 July 2017 at 13:06, Peter Cock <p.j.a.cock at googlemail.com> wrote:
>>
>> Hmm. Do you need this to work on Python 2?
>>
>> https://docs.python.org/2/library/urllib.html
>> https://docs.python.org/3/library/urllib.request.html
>>
>> Python 3 added a timeout argument to the urlopen function,
>> which it says defaults to the "global default timeout".
>>
>> Does this help:
>>
>> import socket
>> socket.setdefaulttimeout(30)  # timeout in seconds
>>
>> I'm guessing at a sensible limit here - you will
>> probably need to experiment.
>>
>> Regards,
>>
>> Peter
>>
>> On Wed, Jul 26, 2017 at 12:26 PM, Pejvak Moghimi
>> <pejvak.moghimi at york.ac.uk> wrote:
>> > Hi all,
>> >
>> > I'm working on a script to to do blast using the ncbiWWW module, but
>> > very
>> > often one query sequence takes way too long, if at all, to return with
>> > results. This is always, in my experience, immediately solved if I just
>> > stop
>> > the script and re-run it (for the same query sequence); I get the
>> > results as
>> > quickly as I did for the other query sequences.
>> >
>> > I think this hints that this is something to do with ncbi servers. So,
>> > in
>> > order to tackle it, I need to simply modify my while loop to stop and
>> > re-run
>> > the "ncbiwww.qblast(..." line, if it takes longer than a reasonable
>> > length
>> > of time (I do understand shorter than a certain waiting-time would not
>> > be
>> > allowed by ncbi).
>> >
>> > I have no idea how to tackle this, except by either multithreading (not
>> > so
>> > sure how to go on about this though) or changing the qblast script
>> > (locally
>> > of course).
>> >
>> > I would really appreciate any help. Please do let me know if you would
>> > like
>> > to have a look at the script.
>> >
>> > Cheers,
>> > Pej.
>> >
>> > _______________________________________________
>> > Biopython mailing list  -  Biopython at mailman.open-bio.org
>> > http://mailman.open-bio.org/mailman/listinfo/biopython
>
>


More information about the Biopython mailing list