[issue25619] Exception AttributeError: "'NoneType'.... thrown on exit

2015-11-14 Thread R. David Murray

R. David Murray added the comment:

Yes, well, that is part of the fragility of python2's shutdown garbage 
collection, and one of the reasons it got improved.  Changing the name of a 
function can change the order things get retrieved from various internal 
dictionaries, because they are hash tables.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25619] Exception AttributeError: "'NoneType'.... thrown on exit

2015-11-13 Thread R. David Murray

R. David Murray added the comment:

Yes, python2 shutdown has this problem: modules and their attributes are set to 
None during interpreter shutdown.  Things are much better in python3.  If you 
want to avoid the error messages, finalize the objects explicitly (making sure 
to break gc cycles) before the end of your program, or keep explicit references 
to the objects you need during __del__ (eg: os_path = os.path in the global 
scope of your module).

As for your last comment, you are correct, the GC cleanup order is not 
deterministic.

--
nosy: +r.david.murray
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25619] Exception AttributeError: "'NoneType'.... thrown on exit

2015-11-13 Thread R. David Murray

R. David Murray added the comment:

Best practice, by the way, is to be explicit about the scope of any resource 
and clean it up before program end...this is often done by using the context 
manager protocol.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25619] Exception AttributeError: "'NoneType'.... thrown on exit

2015-11-13 Thread terry

New submission from terry:

The attached code generates this output:

init called
finished init
init called
finished init
init called
finished init
initPorts done
alldone
destroying /sys/class/gpio/gpio16/
destroying /sys/class/gpio/gpio6/
Exception AttributeError: "'NoneType' object has no attribute 'path'" in > ignored
destroying /sys/class/gpio/gpio13/
Exception AttributeError: "'NoneType' object has no attribute 'path'" in > ignored

It is necessary to have two functions defined (railVarRes() and 
batleveltopct()) and further more changing the name of railVarRes to 
arailVarRes changes the behavior:


init called
finished init
init called
finished init
init called
finished init
initPorts done
alldone
destroying /sys/class/gpio/gpio16/
destroying /sys/class/gpio/gpio13/
destroying /sys/class/gpio/gpio6/
Exception AttributeError: "'NoneType' object has no attribute 'path'" in > ignored


notice that the order of the class destruction has changed.

--
files: bug.py
messages: 254612
nosy: Terry Garyet
priority: normal
severity: normal
status: open
title: Exception AttributeError: "'NoneType'  thrown on exit
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file41032/bug.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25619] Exception AttributeError: "'NoneType'.... thrown on exit

2015-11-13 Thread terry

terry added the comment:

My real application (not this example code that also 'breaks') is a battery 
monitor that starts at boot time and only exits when the battery is near death. 

So there is effectively a while(batlevelgood) loop that polls the battery level 
and doesn't exit until  near battery death.

I only encounters this while debugging and having to kill (ctrl-c) the script, 
having no chance to clean up properly.

Admittedly I'm not very experienced in Python but I am an experienced 
programmer.  I will look up context mgr protocol, but this was certainly odd 
behavior.  It isn't every day that the name of a  function not even called 
changes observed program behavior.

Terry

> On Nov 13, 2015, at 1:42 PM, R. David Murray <rep...@bugs.python.org> wrote:
> 
> 
> R. David Murray added the comment:
> 
> Best practice, by the way, is to be explicit about the scope of any resource 
> and clean it up before program end...this is often done by using the context 
> manager protocol.
> 
> --
> 
> ___
> Python tracker <rep...@bugs.python.org>
> <http://bugs.python.org/issue25619>
> _______

--
title: Exception AttributeError: "'NoneType'  thrown on exit -> Exception 
AttributeError: "'NoneType' thrown on exit

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25619>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com