[mod_python] Object persistence?

Fredrik Sandin fredrik.sandin at ltu.se
Mon Aug 28 06:34:18 EDT 2006


On Sat, 26 Aug 2006 05:36:14 +0200, Graham Dumpleton  
<grahamd at dscpl.com.au> wrote:
>
> On 25/08/2006, at 11:16 PM, Fredrik Sandin wrote:
>
>>
>> Hello!
>>
>> I am new to mod_python and could need some advice. I want to create an
>> online GUI with mod_python for an existing application written in  
>> Python.
>>
>> The Python application organizes distributed computations and therefore
>> maintains network connections to a number of computers. Users post jobs,
>> which are sent somewhere for execution and then the result is sent back
>> by a callback function. Illustration of principle:
>>
>> class MyComputerCluster:
>> 	def __init__(self, callback):
>> 		self.callback = callback
>> 		...
>> 	def post_job(self, description):
>> 		...
>>
>> def mycallback(userid, result):
>> 	print 'User %d requested: %s' % (userid, result)
>>
>> mycluster = MyComputerCluster(mycallback)
>> mycluster.post_job('compute the meaning of 42')
>> ...
>>
>> Now, there is one major issue - Is it possible to create an object of  
>> type
>> MyComputerCluster for each user of the online GUI and keep it in memory
>> between calls, without spoiling the network connections maintained by  
>> the
>> object? Session variables can be used as reference for a persistent  
>> object,
>> but how to create it?
>>
>> A solution would be to write an independent service that creates the
>> objects and listens for requests (post_job, get_result), but that takes
>> time...
>
> Does the code above you give as an example already exist and a part of
> your existing Python application? What framework is your application for
> performing the distributed jobs written in, or is it some home grown  
> custom
> framework?
>
> I have a sense of what you want to do, but because no real information is
> provided about the existing application or what framework it uses, it is  
> hard
> to give any advice.
>
> Anyway, if the issue is more about how handlers in mod_python might
> communicate with your application, you might look at XML-RPC using the
> xmlrpclib module in Python. Depending on the framework the application
> uses though, it may not be possible to embed an XML-RPC server in the
> application which could respond to the handlers run under mod_python.
>
> Can you perhaps be clearer about the separation between your mod_python
> handlers and your application and how you intend communicating between
> the two.
>
> Graham


Dear Graham,

yes, the code I gave as an example represents an existing Python
application. It is home-gown, so your suggestion to embed an XML-RPC
server could do the trick, will have a closer look at it. Thanks!

By the way, why is it so difficult to support persistent objects,
a "state", from one call to the next? The mod_php application itself
has a state, and each user can be associated with a sessid, so the
problem must be that a user could be served by different mod_php
processes from one call to the next?

In that case, would it not be possible to use the sessid to make
sure that a user is served by the same mod_php process as long
as the session is valid?

Cheers,
Fredrik


More information about the Mod_python mailing list