[issue20836] Pickle Nonetype
New submission from Hans Polak: This simple code works, but I have two 'import pickle' lines. The none working code has one 'import pickle' outside the class definition. This raises a Nonetype error in the pickle module, in the __del__ method. I'd like to know why and I think it's a bug, or is it? class Login(): users = {} def __init__(self): try: with open('user.data','rb') as f: import pickle self.users = pickle.load(f) # print('init: {}'.format(self.users)) except Exception: #'user.data' file doesn't exist pass def __del__(self): try: with open('user.data','wb') as f: # print('del: {}'.format(self.users)) # print(type(self.users)) # print(type(f)) import pickle pickle.dump(self.users, f, pickle.HIGHEST_PROTOCOL) except Exception as e: print('__del__ Shit happened: {}'.format(e)) ---------- assignee: docs@python components: Documentation messages: 212598 nosy: Hans.Polak, docs@python priority: normal severity: normal status: open title: Pickle Nonetype type: behavior versions: Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20836> _______________________________________
R. David Murray added the comment: Before python 3.4, __del__ methods are problematic. During interpreter shutdown various module attributes get set to None, which is probably what is triggering the error. It is unlikely there is a Python bug here: it is a known and documented issue that module attributes can disappear (get set to None) before __del__ methods are run, if objects are not GCed before interpreter shutdown starts. (Pre 3.4. In 3.4 this situation is much improved.) ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20836> _______________________________________
Changes by Serhiy Storchaka <storchaka@gmail.com>: ---------- resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20836> _______________________________________
participants (3)
-
Hans Polak
-
R. David Murray
-
Serhiy Storchaka