{"action":"created","issue":{"url":"https://api.github.com/repos/uqfoundation/dill/issues/195","repository_url":"https://api.github.com/repos/uqfoundation/dill","labels_url":"https://api.github.com/repos/uqfoundation/dill/issues/195/labels{/name}","comments_url":"https://api.github.com/repos/uqfoundation/dill/issues/195/comments","events_url":"https://api.github.com/repos/uqfoundation/dill/issues/195/events","html_url":"https://github.com/uqfoundation/dill/issues/195","id":193008611,"number":195,"title":"Loading the same session after dump creates a different file","user":{"login":"sb2nov","id":1517779,"avatar_url":"https://avatars.githubusercontent.com/u/1517779?v=3","gravatar_id":"","url":"https://api.github.com/users/sb2nov","html_url":"https://github.com/sb2nov","followers_url":"https://api.github.com/users/sb2nov/followers","following_url":"https://api.github.com/users/sb2nov/following{/other_user}","gists_url":"https://api.github.com/users/sb2nov/gists{/gist_id}","starred_url":"https://api.github.com/users/sb2nov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sb2nov/subscriptions","organizations_url":"https://api.github.com/users/sb2nov/orgs","repos_url":"https://api.github.com/users/sb2nov/repos","events_url":"https://api.github.com/users/sb2nov/events{/privacy}","received_events_url":"https://api.github.com/users/sb2nov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-02T01:20:39Z","updated_at":"2016-12-02T08:39:33Z","closed_at":null,"body":"I have some trouble understanding why the file `c.pkl` would be different from `b.pkl` as we're loading the session we just dumped. Thank you for the help. \r\n\r\n```\r\nimport dill\r\nimport os\r\nimport tempfile\r\n\r\ntmpdir = tempfile.mkdtemp()\r\n\r\nclass A(object):\r\n  def __init__(self, a=5):\r\n    self.a = a\r\n\r\n  def printa(self):\r\n    print self.a\r\n\r\nprint 'Directory Path', tmpdir\r\ndill.dump_session(os.path.join(tmpdir, 'b.pkl'))\r\ndill.load_session(os.path.join(tmpdir, 'b.pkl'))\r\ndill.dump_session(os.path.join(tmpdir, 'c.pkl'))\r\ndill.load_session(os.path.join(tmpdir, 'c.pkl'))\r\ndill.dump_session(os.path.join(tmpdir, 'd.pkl'))\r\ndill.load_session(os.path.join(tmpdir, 'd.pkl'))\r\ndill.dump_session(os.path.join(tmpdir, 'e.pkl'))\r\ndill.load_session(os.path.join(tmpdir, 'e.pkl'))\r\ndill.dump_session(os.path.join(tmpdir, 'f.pkl'))\r\ndill.load_session(os.path.join(tmpdir, 'f.pkl'))\r\n\r\nfrom subprocess import check_output\r\nprint 'Hash of all the files: '\r\nprint check_output(\"sha1sum \" + os.path.join(tmpdir, '*'), shell=True)\r\n```\r\n\r\nSample output\r\n```\r\nHash of all the files: \r\nd03af7a9fda8f141cb75ef787c2bc274609edd43  /tmp/sourabhbajaj/tmp7rsR3h/b.pkl\r\nc57c16d3ddaaaf2954aa550f699607baa74e6edd  /tmp/sourabhbajaj/tmp7rsR3h/c.pkl\r\nc57c16d3ddaaaf2954aa550f699607baa74e6edd  /tmp/sourabhbajaj/tmp7rsR3h/d.pkl\r\nc57c16d3ddaaaf2954aa550f699607baa74e6edd  /tmp/sourabhbajaj/tmp7rsR3h/e.pkl\r\nc57c16d3ddaaaf2954aa550f699607baa74e6edd  /tmp/sourabhbajaj/tmp7rsR3h/f.pkl\r\n```\r\n\r\ncc: @mmckerns "},"comment":{"url":"https://api.github.com/repos/uqfoundation/dill/issues/comments/264401964","html_url":"https://github.com/uqfoundation/dill/issues/195#issuecomment-264401964","issue_url":"https://api.github.com/repos/uqfoundation/dill/issues/195","id":264401964,"user":{"login":"matsjoyce","id":6631310,"avatar_url":"https://avatars.githubusercontent.com/u/6631310?v=3","gravatar_id":"","url":"https://api.github.com/users/matsjoyce","html_url":"https://github.com/matsjoyce","followers_url":"https://api.github.com/users/matsjoyce/followers","following_url":"https://api.github.com/users/matsjoyce/following{/other_user}","gists_url":"https://api.github.com/users/matsjoyce/gists{/gist_id}","starred_url":"https://api.github.com/users/matsjoyce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matsjoyce/subscriptions","organizations_url":"https://api.github.com/users/matsjoyce/orgs","repos_url":"https://api.github.com/users/matsjoyce/repos","events_url":"https://api.github.com/users/matsjoyce/events{/privacy}","received_events_url":"https://api.github.com/users/matsjoyce/received_events","type":"User","site_admin":false},"created_at":"2016-12-02T08:39:33Z","updated_at":"2016-12-02T08:39:33Z","body":"You can use `pickletools.dis(open(\"c.pkl\"))` to get a closer look. There's so much stuff that happens in dump/load_session that it's not surprising something changed. It seems in this case that in the first dump, pickle reuses some of the strings it defines, while in the following cases it redefines them. If you print the id of `A.__name__`, it changes after each load so I guess the first time `\"A\"` is shared with something else, say the module `__dict__`, but after dump+load, it is no longer shared and so pickle serializes it twice. Pickle has tons of oddities like this (dict randomisation also has effects like this, but that is between runs) so I wouldn't rely on hashes to check for differences. If you want a more stable storage, use a hacked version of json which sorts dicts before dumping (what I did in the past). Bonus is that it is readable."}}
{"actor":{"display_login":"matsjoyce"}}