timeout, thread, and external connections
Hi, I'm writing a tool similar to MatlabDA for the open-source stat package 'R'. Since R isn't thread safe and is very stateful, I've written code to start up, communicate with, and close independent R processes. This is all working properly. Now, I want to the connection to the external process to 'timeout' after a period of inactivity, so I won't end up with an slowly increasing number of R processes hanging around not doing anything. I have code to 'pickle' the session information and terminate the external R process and to start up a new process and 'unpickle' the state. This will let me 'restore' the connection when a new request comes in. What I don't have is code to implement the timeout feature. Is there as 'standard' method for doing this within Zope? My initial thought is to create a new thread when the connection object is created. Its sole purpose will be to sleep for the timeout length, check whether the connection object has been access during the sleep interval. If it has, then it will reset reset the counter and go back to sleep. If there has not been any access, it will lock the connection object, call the pickle routine, close the connection, and terminate itself. Has anyone else implemented something like this? Are there any 'gotchas' or problems threading under zope. Are there other, better, strategies? For instance, is there a 'callback after interval' function exposed by zope to remove the need for the new thread? Thanks, Greg LEGAL NOTICE Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.
Warnes, Gregory R writes:
... Now, I want to the connection to the external process to 'timeout' after a period of inactivity I would not worry about my own timeouts or my own process management but delegate that to the ZODB.
When you assign a process wrapper for your process to a "_v_" attribute, then the wrapper instance is destroyed when the objects is flushed from the ZODB cache. This would be a good time to kill the process. Dieter
participants (2)
-
Dieter Maurer -
Warnes, Gregory R