On Thursday 20 February 2003 9:48 pm, Jamie Heilman wrote:
Toby Dickenson wrote:
Read the code. It allows medusa-registered sockets to manage the shutdown process.
OK, so if one had a Product that they wanted to be lifetime aware, do you have an example of how one could one use this API?
I hope youve read the documentation in Lifetime.py. I include it below. First you need to work out what phase of the shutdown process you need to take action in, or delay. The easiest example is from the HTTP Server. It includes this code to close the listening socket (the socket that receives new connections) in phase 2 def clean_shutdown_control(self,phase,time_in_this_phase): if phase==2: self.log_info('closing HTTP to new connections') self.close() Sockets for http clients have this code that keeps zope in shutdown phase 3 for as long as there is still a request in progress. def clean_shutdown_control(self,phase,time_in_this_phase): if phase==3: # This is the shutdown phase where we are trying to finish processing # outstanding requests, and not accept any more self.no_more_requests = 1 if self.working or self.writable(): # We are busy working on an old request. Try to stall shutdown return 1 else: # We are no longer busy. Close ourself and allow shutdown to proceed self.close() return 0 # The shutdown phase counts up from 0 to 4. # # 0 Not yet terminating. running in main loop # # 1 Loss of service is imminent. Prepare any front-end proxies for this happening # by stopping any ICP servers, so that they can choose to send requests to other # Zope servers in the cluster. # # 2 Stop accepting any new requests. # # 3 Wait for all old requests to have been processed # # 4 Already terminated # # It is up to individual socket handlers to implement these actions, by providing the # 'clean_shutdown_control' method. This is called intermittantly during shutdown with # two parameters; the current phase number, and the amount of time that it has currently # been in that phase. This method should return true if it does not yet want shutdown to # proceed to the next phase. -- Toby Dickenson http://www.geminidataloggers.com/people/tdickenson