{"action":"closed","issue":{"url":"https://api.github.com/repos/dwf/picklable_itertools/issues/24","labels_url":"https://api.github.com/repos/dwf/picklable_itertools/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/dwf/picklable_itertools/issues/24/comments","events_url":"https://api.github.com/repos/dwf/picklable_itertools/issues/24/events","html_url":"https://github.com/dwf/picklable_itertools/issues/24","id":57354036,"number":24,"title":"Picklable file iterator?","user":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dwf/picklable_itertools/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-11T18:11:48Z","updated_at":"2015-02-11T20:57:40Z","closed_at":"2015-02-11T20:57:40Z","body":"@dwf Wondering if you consider this within the scope of the framework.\r\n\r\nFile handles are iterators, and they can't be pickled.\r\n\r\n```python\r\n>>> f = open('README.md')\r\n>>> f\r\n<open file 'README.md', mode 'r' at 0x7f13b1360d20>\r\n>>> it = iter(f)\r\n>>> it\r\n<open file 'README.md', mode 'r' at 0x7f13b1360d20>\r\n>>> next(it)\r\n'picklable_itertools\\n'\r\n>>> cPickle.dumps(it)\r\nTypeError: can't pickle file objects\r\n```\r\n\r\nAnalogously to `ordered_sequence_iterator`, can I add a `file_iterator`? It will be a bit more involved, because it needs to handle a variety of things through custom `__getstate__` and `__setstate__` methods:\r\n\r\n* Upon pickling, close and remove file handle\r\n* When unpickling, re-open the file, re-iterate over the lines until we get back to where we were\r\n* Have sensible defaults for if the file is not available in the unpickled environment, is no longer writable, etc. Dill implements all of this, so we can steal a lot of the behaviour from there."}}