[mod_python] All spawned threads in Restricted Exection Mode

Alan Davies alan at goatpunch.com
Wed Mar 30 22:39:50 EST 2005


On Wed, 30 Mar 2005 18:28:26 -0500, "Graham Dumpleton"
<grahamd at dscpl.com.au> said:
> In the main it always seems to involve third party packages which are
> non trivial or may be hard to install which makes it a harder process for
> someone else to try and duplicate it. PIL as a third party package
> doesn't
> have strange runtime requirements such as a database needing to be
> created, so try and get as small an example as possible put together
> and post here on the list and I at least can try it and see if I see the
> problem. I would be testing it on Mac OS X, Apache 2.X and Python 2.3.
> 
> In the multithreaded stuff I am doing at the moment, I personally don't
> have problems and mine is probably a stranger arrangement than most. :-)
> 
> Graham

Mine is a very simple arrangement, there's not even any need to bring
PIL
into the picture to reproduce the problem. I've written a short example
script
attempts to open a file, which is just one of the many things not
possible
in restricted mode.

The script can be run here:

http://goatpunch.com:8080/flow/threadtest.py

The output is:

In main thread: file() was OK
In child thread: file() threw exception: file() constructor not
accessible in restricted mode


------ threadtest.py ------

import threading, time, mod_python

def openfiletest(req):
    try:
        a = file("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 mod_python.apache.OK

---------------------------


I added the following to httpd.conf to execute the above script:


<Directory "C:/[...]/htdocs/flow">

  Options Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all

  AddHandler python-program .py
  PythonDebug On 

  <Files threadtest.py>
      PythonPath "['C:/[...]/htdocs/flow'] + sys.path"
      PythonHandler threadtest
  </Files>
</Directory>


Thanks for any help or advice you're able to offer- let me know if
you have any ideas for other code I could run to help narrow down
this problem.

--Alan


More information about the Mod_python mailing list