[mod_python] mod_python and threading.Thread doesn't start

Graham Dumpleton grahamd at dscpl.com.au
Mon Jun 6 07:24:55 EDT 2005


I have been developing an idea of what is wrong. Can you now try this 
slightly
different variation on the code and post back the result. Am interested 
in the
id of "__builtins__" and whether it is the same as 
"__builtin__.__dict__". On
my system they are actually the same object. Note this problem was 
possibly
only introduced with 2.3.5 and 2.4.

import threading
import time
from mod_python import apache

import __builtin__

def openfiletest(req):
     req.write(" builtins=%d "%id(__builtins__))
     req.write(" builtin=%d "%id(__builtin__.__dict__))
     try:
         a = file("/tmp/test", "w")
         req.write("file() was OK\n")
     except Exception, e:
         req.write("file() threw exception: " + str(e) + "\n")

def handler(req):
     req.write("In main thread: ")
     openfiletest(req)
     req.write("In child thread: ")
     t = threading.Thread(target=openfiletest, args=(req,) )
     t.start()
     time.sleep(1)
     return apache.OK

On 06/06/2005, at 9:14 PM, Alexey Melchakov wrote:

>
> You were right, it's all about restricted mode. Is there any solvation 
> for this problem?
>
> Output:
>
> In main thread: file() was OK
> In child thread: file() threw exception: file() constructor not 
> accessible in restricted mode
>
>
>
> On 6/6/05, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
>
> On 06/06/2005, at 5:39 PM, Alexey Melchakov wrote:
>
> Try the following code instead so that you can see if a Python
> exception is
> being raised within the thread. One possibility is that you might be
> running
> up against a strange problem seen by a few people which hasn't really
> been
> worked out yet. One previous post where someone had this problem was:
>
>    
> http://www.modpython.org/pipermail/mod_python/2005-January/017129.html
>
> for more details.
>
> Anyway, let us know what the following produces.
>
>
> import threading
> import time
> from mod_python import apache
>
> def openfiletest(req):
>      try:
>          a = file("/tmp/test", "w")
>          req.write("file() was OK\n")
>      except Exception, e:
>          req.write("file() threw exception: " + str(e) + "\n")
>
> def handler(req):
>      req.write("In main thread: ")
>      openfiletest(req)
>      req.write("In child thread: ")
>      t = threading.Thread(target=openfiletest, args=(req,) )
>      t.start()
>      time.sleep(1)
>      return apache.OK
>
>
>
> -- 
> melchakov at gmail.com
> CRV-RIPN



More information about the Mod_python mailing list