[mod_python] How create a scheduler ?

Graham Dumpleton grahamd at dscpl.com.au
Sat Nov 18 07:00:36 EST 2006


On 18/11/2006, at 10:41 PM, Nic James Ferrier wrote:

> "Alex Greif" <alex.greif at gmail.com> writes:
>
>> Hi,
>> how about creating a cron entry that create a http request?
>>
>> Alex.
>>
>> On 11/18/06, Seb <seb.dailly at gmail.com> wrote:
>>> Hello,
>>>
>>> I would like to know if we can create a scheduler inside  
>>> mod_python. I
>>> seems that the threads are not "persistents" and are closed when the
>>> page is load. Is there any particular way for keeping a running  
>>> thread
>>> ? ( It is not for generating html but for periodic saves and data
>>> updates )
>
> You could fork another process.

You can use the PythonImport directive to have a specific module  
imported
at the time that the Apache child process is created and prior to any  
actual
request having been received. From this you could create a new thread to
perform some periodic task.

As with any thread programming, you have to deal with all the  
concurrency
issues. Using mod_python you also have to deal with issues of automatic
module reloading. As such, you are best ensuring that any distinct  
thread
only operates within the context of modules which will not be  
candidates for
automatic module reloading. If you don't ensure this, things could  
screw up
quite badly. You also need to be mindful that there can be multiple  
Apache
child processes. This can be an issue if the thread is going to have  
to update
stuff on disk as well as you need to have external locking such that the
separate child processes don't interfere with each other.

For more information on the Apache/mod_python process/thread/interpreter
model read:

   http://www.dscpl.com.au/wiki/ModPython/Articles/ 
TheProcessInterpreterModel

BTW, what exactly is it that you want the thread to do?

Graham


More information about the Mod_python mailing list