[Zope] atexit.register() doesn't work

Jens Wolk jewo_lists@gmx.de
Sat, 18 May 2002 21:29:39 +0200


Hi everybody,

in a python based product (running on a Zope 2.5.0 installation) I try to 
implement a class which hands out unique ids. (*) The idea is to save the 
last id in the server's file system. To make sure that this works even if the 
Zope server crashed, the object should save an 'earmark' in the file system 
if it is destroyed in a regular way.

I tried to do this with the atexit module provided by Python, but it doesn't 
work. (nor does __del__). Does anybody know why this is so? Or can anybody 
suggest a working alternative?

(One working solution provided by alex.khan (*) is to patch the source code of 
Zope itself. But I would like to find another solution, so that others who 
might want to use the product, have not to fiddle with the Zope source code.)

Here are the relevant parts of the implementation:

class ManageGlobalZypId:
    def __init__(self, bucketSize, FileName):
        import os, thread, string, App.FindHomes, atexit
	
	...

        self.opened = 1
        atexit.register(self.close)
        
    def close(self):
        if self.opened:
            # save 'earmark'
            self.opened = 0
                            
    ...
          
# GlobalIdHandout is the one and only object from which other objects get
# their ids
GlobalIdHandout = ManageGlobalZypId(256, 'GSID.txt') 

Thank you.

Jens

(*) based on an idea by alex.khan:
http://www.zope.org/Members/alex.khan/GlobalSystemId?pp=1