Davide Alberani | 24 Mar 2012 12:56
Picon
Gravatar

Re: timing out

On Sat, Mar 24, 2012 at 11:51, Tomáš Hnyk <tomashnyk <at> gmail.com> wrote:
>
> and it has been hanging at this for about two minutes now and counting.
> Should not it raise some sort of exception, or is it going to wait for
> something indefinitely?

:-/
It's very possible that it will wait until the end of time, I fear.

> I was originally asking if there were a way to set a timeout to retrieving
> film info. Is there some internal timeout in imdbpy after which it justs
> gives up?

My fault: I misunderstood the problem.
No, IMDbPY uses urllib, and it doesn't provide a way to set
a timeout.  urllib2 has it, but only in very recent python versions,
so I'd prefer not to use it (and, by the way, a conversion from urllib
to urllib2 would take me some time).

> I found a way to do this on in internet:
> import signal

Yes, it's more or less reasonable, but I want to think twice about
it, before I introduce an alarm in the IMDbPY code... after
all i's a library and it could heavily interfere with signal handling
made by the programs that uses it. :-(

Real point is, it's very strange that it happens so methodically on
your system... I think I've never seen it hangs during a request.

(Continue reading)

Tomáš Hnyk | 24 Mar 2012 13:10
Picon

Re: timing out

On Sat, 24 Mar 2012 12:56:09 +0100, Davide Alberani  
<davide.alberani@...> wrote:

>> I was originally asking if there were a way to set a timeout to  
>> retrieving
>> film info. Is there some internal timeout in imdbpy after which it justs
>> gives up?
>
> My fault: I misunderstood the problem.
> No, IMDbPY uses urllib, and it doesn't provide a way to set
> a timeout.  urllib2 has it, but only in very recent python versions,
> so I'd prefer not to use it (and, by the way, a conversion from urllib
> to urllib2 would take me some time).
>
Understood.

>> I found a way to do this on in internet:
>> import signal
>
> Yes, it's more or less reasonable, but I want to think twice about
> it, before I introduce an alarm in the IMDbPY code... after
> all i's a library and it could heavily interfere with signal handling
> made by the programs that uses it. :-(
>
Well, I think this'd better stay in programs that use IMDbPy, for the very  
reasons you stated.

> Real point is, it's very strange that it happens so methodically on
> your system... I think I've never seen it hangs during a request.
Yeap, it does not happen always, but pretty often. Usually, trying to run  
(Continue reading)

Davide Alberani | 24 Mar 2012 16:07
Picon
Gravatar

Re: timing out

On Sat, Mar 24, 2012 at 13:10, Tomáš Hnyk <tomashnyk <at> gmail.com> wrote:
>
>>  import socket
>>  socket.setdefaulttimeout(10)
>>
>> With that, at least the 'open' should fail after at most 10 seconds.
>
> Hm, this seems to work, thanks!

Ah, great!

> BTW: when it hangs and I stop it with ctrl+C, this is what ipython tells me:

Yep, it stalls on the read.  I thought that the setdefaulttimeout would have
fixed only problems at opening the socket... better this way. :-)

I've introduced a 'timeout' parameter, set by default to 30 seconds.
Please anyone report any strange behavior. :-)

It can be used from programmatically or from the configuration file,
as usual.

Thanks again!

--

-- 
Davide Alberani <davide.alberani <at> gmail.com>  [PGP KeyID: 0x465BFD47]
http://www.mimante.net/

------------------------------------------------------------------------------
This SF email is sponsosred by:
(Continue reading)


Gmane