Issue Details (XML | Word | Printable)

Key: MODPYTHON-118
Type: Wish Wish
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

Allow PythonImport to optionally call function in module.

Created: 03/Feb/06 11:29 AM   Updated: 05/Apr/07 11:39 AM
Return to search
Component/s: core
Affects Version/s: 3.3.x
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

Resolution Date: 17/Mar/06 12:17 PM


 Description  « Hide
PythonImport can currently be used to specify that a module be imported into a named interpreter at the time that an Apache child process is initiated. Because all it does is import the module, if any specific action needs to be triggered, it has to be done as a side effect of the module import.

Triggering actions as a side effect of a module import is generally not a good idea as failure of the side effect action will cause the import of the module itself to fail if the code doesn't properly handle this situation. It is generally preferable to import the module and when that has suceeded only then call a specific function contained in the module to initiate the action.

Thus proposed that PythonImport be able to take an optional function to be called upon successful import of the name module. The syntax would be like that for Python*Handler directives.

  PythonImport mymodule::myfunc myinterpreter

This would have the effect of loading module "mymodule" in the interpreter called "myinterpreter" and then calling "mymodule.myfunc()". No arguments would be supplied to the function when called.

Another benefit of this feature would be that it would allow a single module to be able to contain a number of special initialisation functions that might be triggerable. The user could selectively call those that might be required.

  PythonImport mymodule::enable_caching myinterpreter
  PythonImport mymodule::disable_logging myinterpreter

At the moment to do that, a distinct module would need to be created for each where the only thing in the module is the call of the function.

Note that in using something similar to mod_python option/config values, am talking here about options that must be able to only be enabled/disable in one spot. The problem with mod_python option/config values in Apache is that different parts of the document tree can set them to different values, which for some things is actually a problem, such as the case with PythonAutoReload.









 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Graham Dumpleton made changes - 11/Mar/06 08:27 AM
Field Original Value New Value
Assignee Graham Dumpleton [ grahamd ]
Graham Dumpleton made changes - 11/Mar/06 08:28 AM
Status Open [ 1 ] In Progress [ 3 ]
Graham Dumpleton added a comment - 11/Mar/06 08:34 AM
It might also be appropriate that the function that can be registered to be called be passed a single argument which is the "server" object. Ie., same as "req.server" that request handlers have access to. This would give access to "server.get_options()" and other information about the server.This though means that you would have to wrap existing methods with no argument that weren't interested in the "server" object.

Alternatively, go with no argument as proposed, but the "apache._server" and "apache._interpreter" attributes be renamed to "apache.server" and "apache.interpreter" and be officially sanctioned as part of the public API of mod_python. Being public, they would then also be useable from global scope within any module which has been imported. This is probably a preferable path to take.

Repository Revision Date User Message
ASF #386524 Fri Mar 17 04:14:22 UTC 2006 grahamd PythonImport directive now uses apache.import_module() to import modules
to avoid issues with modules being loaded multiple times. (MODPYTHON-113)
PythonImport directive now allows function within module to be optionally
specified where function is called after module has been successfully
imported. (MODPYTHON-118)
Files Changed
MODIFY /httpd/mod_python/trunk/test/htdocs/tests.py
MODIFY /httpd/mod_python/trunk/Doc/modpython5.tex
MODIFY /httpd/mod_python/trunk/test/test.py
MODIFY /httpd/mod_python/trunk/src/mod_python.c
ADD /httpd/mod_python/trunk/test/htdocs/dummymodule.py
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/apache.py

Graham Dumpleton made changes - 17/Mar/06 12:17 PM
Status In Progress [ 3 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Fix Version/s 3.3 [ 12310101 ]
Graham Dumpleton made changes - 05/Apr/07 11:39 AM
Status Resolved [ 5 ] Closed [ 6 ]