[mod_python] How to initialize a variable using PythonImport and access it from a Handler?

Graham Dumpleton grahamd at dscpl.com.au
Mon May 2 16:44:19 EDT 2005


You have either hit the weird restricted mode problem that some people  
are
seeing with Python 2.3.5 or later versions of Python, or perhaps it is
simply because you have initialised the variable in the  
"main_interpreter"
yet the request is being handled in a different interpreter. Have you  
named
explicitly the interpreter to be used as "main_interpreter" for part of  
URL
namespace requests are handled in? Ie.,

   PythonInterpreter main_interpreter

By default interpreter will have name something like your hostname and  
thus
would be a distinct interpreter and thus distinct global data space.  
Using
just Python code, you cant access between interpreters.

Graham

On 03/05/2005, at 4:34 AM, jarrod roberson wrote:

> I am trying to get access to a list that is being updated by a Twisted  
> Reactor.
> I do a PythonIport myapp main_interpreter in httpd.conf
> I have a handler that I want to print out the contents of list  
> returned from a function on the global object, but I get this error
>
>
> Any ideas . . .
>
> Mod_python error: "PythonHandler viewZeroConf"
>
> Traceback (most recent call last):
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/mod_python/apache.py", line 287, in  
> HandlerDispatch
>
>     log=debug)
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/mod_python/apache.py", line 457, in  
> import_module
>     module = imp.load_module(mname, f, p, d)
>
>
>   File "/www/viewZeroConf.py", line 2, in ?
>     import myapp
>
>   File "/www/weblife/__init__.py", line 7, in ?
>     from twisted.internet import reactor
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/twisted/internet/reactor.py", line 11, in ?
>
>     from twisted.internet import selectreactor
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/twisted/internet/selectreactor.py", line 22,  
> in ?
>     from
> twisted.internet import posixbase
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/twisted/internet/posixbase.py", line 25, in ?
>     from twisted.internet import tcp, udp
>
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/twisted/internet/tcp.py", line 65, in ?
>     from twisted.internet import protocol, defer, base, address
>
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/twisted/internet/protocol.py", line 25, in ?
>     class Factory:
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/zope/interface/advice.py", line 132, in advise
>
>     return callback(newClass)
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/zope/interface/declarations.py", line 550, in  
> _implements_advice
>     classImplements(cls, *interfaces)
>
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/zope/interface/declarations.py", line 526, in  
> classImplements
>     spec = implementedBy(cls)
>
>   File  
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site-packages/zope/interface/declarations.py", line 364, in  
> implementedByFallback
>
>     spec = cls.__dict__.get('__implemented__')
>
> RuntimeError: class.__dict__ not accessible in restricted mode
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list