This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Pickle Nonetype
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.2
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Hans.Polak, docs@python, r.david.murray
Priority: normal Keywords:

Created on 2014-03-02 22:50 by Hans.Polak, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg212598 - (view) Author: Hans Polak (Hans.Polak) Date: 2014-03-02 22:50
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):
            with open('','rb') as f:
                import pickle
                self.users = pickle.load(f)
#                print('init: {}'.format(self.users))
        except Exception:
            #'' file doesn't exist

    def __del__(self):
            with open('','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))
msg212599 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-02 23:03
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.)
Date User Action Args
2022-04-11 14:57:59adminsetgithub: 65035
2015-11-28 15:43:25serhiy.storchakasetstatus: open -> closed
resolution: not a bug
stage: resolved
2014-03-02 23:03:09r.david.murraysetnosy: + r.david.murray
messages: + msg212599
2014-03-02 22:50:19Hans.Polakcreate