Question: can we store an arbitrary python object (created with external method) in the ZOPE namespace during the life of the current ZOPE server process? If the object is picklable, then we just assign it to an attribute of a folder. The object will survive pickling. But if the object is not picklable, e.g., an open pipe, or an open file, then Zope does not allow it to be assigned to a normal attribute. The solution I used now is to assign the object to an attribute with name starting with _v_, like _v_my_sub_process_pipe. Then the object can be saved, for some period of time, and can be used by other external methods(other than the one created it). But, after a while, the saved _v_ attribute simply dispears. I guess it has been saved to the ODB and then reloaded, but attributes with _v_ name prefix cannot survive pickling, so it is lost. Zope gurus: is there any way to allow saving of arbitrary python object in the running Zope process? I only need the object to live during the server process's life. I need this feature because I'm driving a interactive R process with Zope, users(using web browsers) can submit R programs to the Zope server and get result from Zope. For this, I have a Pipe3 object linked with the R subprocess, if only I could get hold of this Pipe3 object during the server's lifetime, I can interact with it. If other Zope developers want to drive an interactive subprocess through wb server and let web client access the subprocess, this is a general problem we need to solve. Jim Fulton <jim@digicool.com> has mentioned some solution in the previous "Persistent method" thread, but I can't quite understand how to accomplish the task with the current version of Zope.
Li Dongfeng wrote:
Question: can we store an arbitrary python object (created with external method)
Note that external methods are really not appropriate when you have any kind of persistence issues involved.
in the ZOPE namespace during the life of the current ZOPE server process?
If the object is picklable, then we just assign it to an attribute of a folder. The object will survive pickling.
But if the object is not picklable, e.g., an open pipe, or an open file, then Zope does not allow it to be assigned to a normal attribute.
This is as it should be, since it makes to sense to save an open pipe in a database. :)
The solution I used now is to assign the object to an attribute with name starting with _v_, like _v_my_sub_process_pipe. Then the object can be saved, for some period of time, and can be used by other external methods(other than the one created it). But, after a while, the saved _v_ attribute simply dispears. I guess it has been saved to the ODB and then reloaded, but attributes with _v_ name prefix cannot survive pickling, so it is lost.
Right. You have another problem too: if you habe multiple application threads, then two requests to the same logical object may not get the same phisical object. So saving a value in a _v_ attribute does not assure that you will get the value the next time you access the same (logical) object, even if the physical object is not removed from memory.
Zope gurus: is there any way to allow saving of arbitrary python object in the running Zope process? I only need the object to live during the server process's life.
You might be better served to create a global registry of pipes that is keyed on persistent object id and and protected by a lock. This registry might be in a module global variable in a *product* module, *not* an external method file. Jim -- Jim Fulton mailto:jim@digicool.com Python Powered! Technical Director (888) 344-4332 http://www.python.org Digital Creations http://www.digicool.com http://www.zope.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
participants (2)
-
Jim Fulton -
Li Dongfeng