[Zope] i want a timeout interrupt

Dieter Maurer dieter@handshake.de
Wed, 28 Nov 2001 21:55:48 +0100


Horst Wald writes:
 > can one interrupt the execution of a script when a certain amount of time 
 > has passed?
Not easily...

   Signals would be used for such asynchronous events. They have lots of
   restrictions in a multi-threaded environment such as Zope
   (they do not work under most Unix implementations in this context).

 > ... timing out "urllib.urlopen" ...
It may depend on your operating system, whether this is possible or
not. However, you will need to work a bit to get it:

  It is probably best to use "urllib2" and provide your own
  HTTP handler.

  There is a timeout enhanced "socket" module for Python, available
  for some platforms. Search the "comp.lang.python" archives for it.
 
  If you can use it for your platform, then it is quite easy.
  Enhance "httplib" by using the timeout enabled "socket" module.
  Make your own "urllib2.HTTPHandler" to use the enhanced version
  of "httplib" and pass your timeout value.

  Otherwise, you may try to use non-blocking socket operations
  and control the timeouts via "select". In this case,
  you will probably need to implement "urlopen" yourself as
  the used "socket.makefile" will not use a timeout controlled
  "select".
  

Dieter