On Sat, 24 Mar 2012 12:56:09 +0100, Davide Alberani <davide.alber...@gmail.com> 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 it one or two more times is enough, but the program needs to know that it has failed, so that is why I am asking about this. I am running this in ipython console, just the commands I stated (import and then I call imdb.IMDB...) > Anyway, if you can try to put _before_ IMDb is imported/instanced this: > import socket > socket.setdefaulttimeout(10) > > With that, at least the 'open' should fail after at most 10 seconds. Hm, this seems to work, thanks! BTW: when it hangs and I stop it with ctrl+C, this is what ipython tells me: /usr/local/lib/python2.7/dist-packages/IMDbPY-4.9dev_20120324-py2.7-linux-x86_64.egg/imdb/__init__.pyc in get_movie(self, movieID, info, modFunct) 408 if modFunct is not None: 409 movie.set_mod_funct(modFunct) --> 410 self.update(movie, info) 411 return movie 412 /usr/local/lib/python2.7/dist-packages/IMDbPY-4.9dev_20120324-py2.7-linux-x86_64.egg/imdb/__init__.pyc in update(self, mop, info, override) 769 method = lambda *x: {} 770 try: --> 771 ret = method(mopID) 772 except Exception, e: 773 self._imdb_logger.critical('caught an exception retrieving ' \ /usr/local/lib/python2.7/dist-packages/IMDbPY-4.9dev_20120324-py2.7-linux-x86_64.egg/imdb/parser/http/__init__.pyc in get_movie_main(self, movieID) 483 484 def get_movie_main(self, movieID): --> 485 cont = self._retrieve(self.urls['movie_main'] % movieID + 'combined') 486 return self.mProxy.movie_parser.parse(cont, mdparse=self._mdparse) 487 /usr/local/lib/python2.7/dist-packages/IMDbPY-4.9dev_20120324-py2.7-linux-x86_64.egg/imdb/parser/http/__init__.pyc in _retrieve(self, url, size, _noCookies) 430 self._http_logger.debug('fetching url %s (size: %d)', url, size) 431 try: --> 432 ret = self.urlOpener.retrieve_unicode(url, size=size) 433 finally: 434 if _noCookies and _cookies: /usr/local/lib/python2.7/dist-packages/IMDbPY-4.9dev_20120324-py2.7-linux-x86_64.egg/imdb/parser/http/__init__.pyc in retrieve_unicode(self, url, size) 193 if PY_VERSION > (2, 3) and not IN_GAE: 194 kwds['size'] = size --> 195 content = uopener.read(**kwds) 196 self._last_url = uopener.url 197 # Maybe the server is so nice to tell us the charset... /usr/lib/python2.7/socket.pyc in read(self, size) 349 while True: 350 try: --> 351 data = self._sock.recv(rbufsize) 352 except error, e: 353 if e.args[0] == EINTR: KeyboardInterrupt: ------------------------------------------------------------------------------ This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure _______________________________________________ Imdbpy-help mailing list Imdbpy-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/imdbpy-help