Idiom for running compiled python scripts?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Mar 24 21:26:08 EDT 2007


En Sat, 24 Mar 2007 20:46:15 -0300, Mark <mark at mailinator.com> escribió:

> The above doesn't actually work for my test script. I have an atexit
> call in the script which is deleting some temp files and I get the
> following traceback on termination when run with the above:
>
> Error in atexit._run_exitfuncs:
> Traceback (most recent call last):
>   File "atexit.py", line 24, in _run_exitfuncs
>     func(*targs, **kargs)
>   File "/home/mark/bin/myscript.py", line 523, in delete
>     if files.tempdir:
> AttributeError: 'NoneType' object has no attribute 'tempdir'

I don't know exactly what happened so it doesn't work anymore (and it  
worked before) but script finalization is always a bit fragile. All values  
in all modules dictionaries (holding globals) are set to None (presumably  
to help garbage collection by breaking cycles). When your delete function  
is called, globals like shutil or files are already gone. A way to avoid  
this problem is to hold a reference to all required globals, so your  
delete function would become:

      @staticmethod
      def delete(files=files,rmtree=shutil.rmtree):
  	'''Called to delete all temp files'''
  	if files.tempdir:
  	    rmtree(files.tempdir)

But I'm not sure if this is enough because rmtree relies on the os module  
to do its work.

-- 
Gabriel Genellina




More information about the Python-list mailing list