[Zope] Isolating changes that can only be done globally

Jonathan dev101 at magma.ca
Mon May 29 20:13:48 EDT 2006

How about a different approach:  use an os.fork or spawn call that launches 
a 'wget' (or equivalent) command into a new process.  Caution: depending on 
how you do this you may get a bunch of dead 'children' processes cluttering 
up the process table and will need to implement some kind of reaper process 
(google is your friend here).



----- Original Message ----- 
From: "Michael Vartanyan" <pycry at doli.biz>
To: <zope at zope.org>
Sent: Monday, May 29, 2006 7:27 PM
Subject: [Zope] Isolating changes that can only be done globally

> Hello All,
> This is probably more a Python question but maybe you will have a quick 
> solution for me - I guess the greatest *multi-threaded* Python application 
> provides the greatest basis for this problem domain :-)
> The situation: external method that is doing a http request using urllib2. 
> I don't care about the response, and whether there was any response at 
> all, I just need to send the request through - thus I want this request to 
> time out very fast (let it be 2 seconds). I found no documented way to set 
> the timeout for urllib2, after some googling I found an advice to 
> manipulate the timeout on the lower-level socket module, something like 
> this:
> import socket
> import urllib2
> def do_request():
>  timeout = 2
>  socket.setdefaulttimeout(timeout)
>  req = urllib2.Request(url='http://my.site.com/do_something_quick')
>  response = urllib2.urlopen(req)
> The problem is this way this default timeout is set for _all_ new socket 
> created by this Python process using the socket module. Even if I return 
> the default to its previous state after the request it won't help me 
> much - there are three more threads in my Zope that should be able to work 
> with default timeout. So there are two possible solutions - to find a 
> (preferably documented) way of accessing and parameterizing the socket 
> object created by urllib2 to make a request or to find a way to 
> isolate(??) global module settings between Zope threads.
> Zope 2.8.3, Python 2.4.2, FreeBSD 4.10 if this is relevant.
> Any hints/TFMs?
> Many thanks
> Michael
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )

More information about the Zope mailing list