[mod_python] Object persistence?

Graham Dumpleton grahamd at dscpl.com.au
Fri Aug 25 23:36:14 EDT 2006


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


More information about the Mod_python mailing list