|
1 1
mod_py at ua.fm
Tue Jun 24 11:11:09 EST 2003
Greetings to all,
I'm using Apache 1.3.24 + mod_py 2.7.8.
The idea is to make mod_py have global variables that
will be accessible from any request untill apache restarts.
I added another dictionary to mod_python.c next to
static PyObject * interpreters = NULL;
like:
PyObject * python_globals = NULL;
I initialize it on apache start in
void python_init(server_rec *s, pool *p)
like:
if (!python_globals)
{
python_globals = PyDict_New();
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
"python_init: Initializing globals dict");
}
and logging shows it really initializes once per apache start.
then I just trying to use it via req object (maybe not the best way but
fastest to me)
I define it as attribute '__globals__' of req object
so it's accessible as req.__globals__
module requestobject.c
procedure
static PyObject * request_getattr(requestobject *self, char *name)
like:
else if (strcmp(name, "__globals__") == 0)
{
Py_INCREF(python_globals);
return (PyObject *) python_globals;
}
works fine with single apache child process.
means I can set
req.__globals__[key] = anyobject
and read it in next page hit
anyobject = req.__globals__[key]
but when I start to use few such apache processes (access it from diff ip) I
have strange situation.
req.__globals__ has same physical address like 0x810108c but different
content.
Even dumping that 'python_globals' dictionary in requestobject.c shows
different content of PyDict object.
It looks like each apache child process has own address space and same address
points
to physically different memory.
Any suggestion has can I fix that?
Thanx,
Anatoly Artamonov
----
-> CTAPT -> http://start.alkar.net
|