You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-dev@quetz.apache.org by David Fraser <da...@sjsoft.com> on 2004/04/06 17:31:26 UTC
server cleanup functions run in restricted mode
Hi
It seems that server cleanup functions registered with
server.register_cleanup run in restricted mode.
I'm trying to use them to close a database connection and being run in
restricted mode causes problems.
I can't see in the code where this gets set, but I get the following error:
[Tue Apr 06 17:16:01 2004] [error] python_cleanup: Error calling cleanup
object <bound method jLogbookMultiServer.onshutdown of
<jLogbook.python.jlogbook.jLogbookMultiServer object at 0x00A62670>>
[Tue Apr 06 17:16:01 2004] [error] exceptions.RuntimeError:
instance.__dict__ not accessible in restricted mode
Is there a reason that the server functions needed to be run in
restricted mode, or is there a better way I should do this?
David
Re: server cleanup functions run in restricted mode
Posted by "Michael C. Neel" <ne...@mediapulse.com>.
Hmm, could this be related then?
We have several sites, all vhosts, that run some code and place a db
handle in a global var (db). Not every request, but frequent enough to
cause concern we get an error that host a tried to run a query on host
b's db object (usually results in a MySQLdb error that the given
database doesn't have table x).
I've tried naming the globals differently, i.e. db1 and db2, but the
problem still occurs. It's also crossed between different handlers and
different hosts - a fixup in server confused with a content in b. The
only thing I've found to avoid the issue is create and destroy the db
inside of the request - which doesn't allow for persistent connections.
FYI I did discover a MySQLdb issue that causes (any version) to not be
able to be garbage collected. Searching sf.net bugs I found the reports
and cause and fixed the version we have. So I'm not ruling out
MySQLdb's role in the problem.
This occurs on 2.7.10 servers (and 2.7.8+), but I have not seen it on
3.x - and given the traffic I have on some of the 3.x boxes I would have
seen it if it was going on. I'm hoping to get a chance to try and
recreate the problem on a test server here shortly.
Mike
Gregory (Grisha) Trubetskoy wrote:
>What version of mod_python is this?
>
>Restricted mode is a strange beast, in that there isn't really anything
>like a "restricted mode" flag, but it looks at a pointer somwhere (don't
>remember now), and if it's not what is expected, it concludes that it's in
>restricted mode. So this behaviour is actually a sign of a bug where an
>object is created in one subinterpreter but is running in another... These
>bugs can be hard to track down.
>
>Grisha
>
>
>On Tue, 6 Apr 2004, David Fraser wrote:
>
>
>
>>Hi
>>
>>It seems that server cleanup functions registered with
>>server.register_cleanup run in restricted mode.
>>I'm trying to use them to close a database connection and being run in
>>restricted mode causes problems.
>>I can't see in the code where this gets set, but I get the following error:
>>[Tue Apr 06 17:16:01 2004] [error] python_cleanup: Error calling cleanup
>>object <bound method jLogbookMultiServer.onshutdown of
>><jLogbook.python.jlogbook.jLogbookMultiServer object at 0x00A62670>>
>>[Tue Apr 06 17:16:01 2004] [error] exceptions.RuntimeError:
>>instance.__dict__ not accessible in restricted mode
>>
>>Is there a reason that the server functions needed to be run in
>>restricted mode, or is there a better way I should do this?
>>
>>David
>>
>>
>>
Re: server cleanup functions run in restricted mode
Posted by David Fraser <da...@sjsoft.com>.
Just for reference, these are the URLs and info I've found on this problem.
There doesn't seem to be much info at all in the Python docs / newsgroups.
I have been trying to set up a testcase but at the moment it crashes
Apache just trying to call a simple servercleanup (with pass) so I need
to work at it a bit...
http://4suite.org/docs/FAQ.xml
> Why do I get codec or other strange errors when running under mod_python?
>
> There is a known problem with mod_python in Python 2.2 and older.
> mod_python is running in restricted mode, and this is considered by
> the mod_python folks to be a bug. Anything which introspects (like
> 4Suite) or does anything a restricted interpreter can't do will fail
> with a cryptic exception. The solution is to upgrade to Python 2.3,
> and use a recent build of mod_python (3.1 or newer).
http://mail.python.org/pipermail/python-list/1999-April/000903.html
(1999 discussion of this problem)
>This alleviates the problem and makes it work. Outside of not
>finalizing interpreters (which alleviates it somewhat, but makes the
>code run in restricted mode since __builtins__ of the unpickled objects
>isn't the same as the "current" __builtins__), I don't know of any other
>way to fix this.
>
http://groups.google.com/groups?th=bfe053aba305ba1c&seekm=35A102B1.182B68A2%40starmedia.net#link1
(1998 discussion of this problem)
>In the course of playing with the pyapache, I've run into the situation
>where the interpreter complains about being in restricted mode. What
>I've been able to figure out is this: if the __builtins__ of the current
>frame is different than the __builtins__ of the current top frame (read
>as current thread), it is in restricted mode. Is this correct?
>
http://groups.google.com/groups?th=fdeaf811901bc4f&seekm=mt2.0-17287-914742573%40news.informatik.uni-bonn.de
(ancient announcement of httpady)
>1. A bug related to the way multiple intrpreters were implemented that would
>occasionally use objects created in one interpreter in another. The bug would manifest
>itself by Python complaining that __dict__ is not available in restricted mode.
>
>
David Fraser wrote:
> mod_python 3.1.3 running on Windows
> Thanks for the explanation, that makes sense why I couldn't find the
> code...
> I'll try and compare the request and server implementations of setting
> the cleanup function and work out why this is happening...
>
> David
>
> Gregory (Grisha) Trubetskoy wrote:
>
>> What version of mod_python is this?
>>
>> Restricted mode is a strange beast, in that there isn't really anything
>> like a "restricted mode" flag, but it looks at a pointer somwhere (don't
>> remember now), and if it's not what is expected, it concludes that
>> it's in
>> restricted mode. So this behaviour is actually a sign of a bug where an
>> object is created in one subinterpreter but is running in another...
>> These
>> bugs can be hard to track down.
>>
>> Grisha
>>
>>
>> On Tue, 6 Apr 2004, David Fraser wrote:
>>
>>
>>
>>> Hi
>>>
>>> It seems that server cleanup functions registered with
>>> server.register_cleanup run in restricted mode.
>>> I'm trying to use them to close a database connection and being run in
>>> restricted mode causes problems.
>>> I can't see in the code where this gets set, but I get the following
>>> error:
>>> [Tue Apr 06 17:16:01 2004] [error] python_cleanup: Error calling
>>> cleanup
>>> object <bound method jLogbookMultiServer.onshutdown of
>>> <jLogbook.python.jlogbook.jLogbookMultiServer object at 0x00A62670>>
>>> [Tue Apr 06 17:16:01 2004] [error] exceptions.RuntimeError:
>>> instance.__dict__ not accessible in restricted mode
>>>
>>> Is there a reason that the server functions needed to be run in
>>> restricted mode, or is there a better way I should do this?
>>>
>>> David
>>>
>>>
>>
>>
>>
>>
>
Re: server cleanup functions run in restricted mode
Posted by David Fraser <da...@sjsoft.com>.
mod_python 3.1.3 running on Windows
Thanks for the explanation, that makes sense why I couldn't find the code...
I'll try and compare the request and server implementations of setting
the cleanup function and work out why this is happening...
David
Gregory (Grisha) Trubetskoy wrote:
>What version of mod_python is this?
>
>Restricted mode is a strange beast, in that there isn't really anything
>like a "restricted mode" flag, but it looks at a pointer somwhere (don't
>remember now), and if it's not what is expected, it concludes that it's in
>restricted mode. So this behaviour is actually a sign of a bug where an
>object is created in one subinterpreter but is running in another... These
>bugs can be hard to track down.
>
>Grisha
>
>
>On Tue, 6 Apr 2004, David Fraser wrote:
>
>
>
>>Hi
>>
>>It seems that server cleanup functions registered with
>>server.register_cleanup run in restricted mode.
>>I'm trying to use them to close a database connection and being run in
>>restricted mode causes problems.
>>I can't see in the code where this gets set, but I get the following error:
>>[Tue Apr 06 17:16:01 2004] [error] python_cleanup: Error calling cleanup
>>object <bound method jLogbookMultiServer.onshutdown of
>><jLogbook.python.jlogbook.jLogbookMultiServer object at 0x00A62670>>
>>[Tue Apr 06 17:16:01 2004] [error] exceptions.RuntimeError:
>>instance.__dict__ not accessible in restricted mode
>>
>>Is there a reason that the server functions needed to be run in
>>restricted mode, or is there a better way I should do this?
>>
>>David
>>
>>
>>
>
>
>
Re: server cleanup functions run in restricted mode
Posted by "Gregory (Grisha) Trubetskoy" <gr...@apache.org>.
What version of mod_python is this?
Restricted mode is a strange beast, in that there isn't really anything
like a "restricted mode" flag, but it looks at a pointer somwhere (don't
remember now), and if it's not what is expected, it concludes that it's in
restricted mode. So this behaviour is actually a sign of a bug where an
object is created in one subinterpreter but is running in another... These
bugs can be hard to track down.
Grisha
On Tue, 6 Apr 2004, David Fraser wrote:
> Hi
>
> It seems that server cleanup functions registered with
> server.register_cleanup run in restricted mode.
> I'm trying to use them to close a database connection and being run in
> restricted mode causes problems.
> I can't see in the code where this gets set, but I get the following error:
> [Tue Apr 06 17:16:01 2004] [error] python_cleanup: Error calling cleanup
> object <bound method jLogbookMultiServer.onshutdown of
> <jLogbook.python.jlogbook.jLogbookMultiServer object at 0x00A62670>>
> [Tue Apr 06 17:16:01 2004] [error] exceptions.RuntimeError:
> instance.__dict__ not accessible in restricted mode
>
> Is there a reason that the server functions needed to be run in
> restricted mode, or is there a better way I should do this?
>
> David
>