{"action":"created","issue":{"url":"https://api.github.com/repos/angr/angr/issues/102","repository_url":"https://api.github.com/repos/angr/angr","labels_url":"https://api.github.com/repos/angr/angr/issues/102/labels{/name}","comments_url":"https://api.github.com/repos/angr/angr/issues/102/comments","events_url":"https://api.github.com/repos/angr/angr/issues/102/events","html_url":"https://github.com/angr/angr/issues/102","id":153320550,"number":102,"title":"KeyError when passing a Path to a function using multiprocessing","user":{"login":"juk80x","id":1790155,"avatar_url":"https://avatars.githubusercontent.com/u/1790155?v=3","gravatar_id":"","url":"https://api.github.com/users/juk80x","html_url":"https://github.com/juk80x","followers_url":"https://api.github.com/users/juk80x/followers","following_url":"https://api.github.com/users/juk80x/following{/other_user}","gists_url":"https://api.github.com/users/juk80x/gists{/gist_id}","starred_url":"https://api.github.com/users/juk80x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juk80x/subscriptions","organizations_url":"https://api.github.com/users/juk80x/orgs","repos_url":"https://api.github.com/users/juk80x/repos","events_url":"https://api.github.com/users/juk80x/events{/privacy}","received_events_url":"https://api.github.com/users/juk80x/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-05T20:40:25Z","updated_at":"2016-05-05T21:58:55Z","closed_at":null,"body":"The following code reproduces the KeyError for any test binary\r\n\r\n```python\r\nimport angr\r\nfrom multiprocessing import Pool\r\n\r\ndef my_test(path):\r\n\treturn path\r\n\r\npool = Pool(processes=4)\r\nproject = angr.Project(\"./testargprog\")\r\nstate = project.factory.entry_state()\r\npath_group = project.factory.path_group(state)\r\npool.apply_async(my_test, (path_group.active[0],))\r\npath_group.step()\r\npool.apply_async(my_test, (path_group.active[0],))\r\npath_group.step()\r\n```\r\n\r\n``` \r\nTraceback (most recent call last):\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py\", line 258, in _bootstrap\r\n    self.run()\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py\", line 114, in run\r\n    self._target(*self._args, **self._kwargs)\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py\", line 102, in worker\r\n    task = get()\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py\", line 378, in get\r\n    return recv()\r\n  File \"/Library/Python/2.7/site-packages/ana/d.py\", line 22, in D\r\n    state = get_dl().load_state(uuid)\r\n  File \"/Library/Python/2.7/site-packages/ana/datalayer.py\", line 69, in load_state\r\n    p = self._state_store[uuid]\r\nKeyError: (('0366d89d-7001-4db4-a375-0a9d80f163a5',), <function D at 0x106e07848>, ('0366d89d-7001-4db4-a375-0a9d80f163a5', <class 'simuvex.s_state.SimState'>, None))\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/angr/angr/issues/comments/217292018","html_url":"https://github.com/angr/angr/issues/102#issuecomment-217292018","issue_url":"https://api.github.com/repos/angr/angr/issues/102","id":217292018,"user":{"login":"zardus","id":3453847,"avatar_url":"https://avatars.githubusercontent.com/u/3453847?v=3","gravatar_id":"","url":"https://api.github.com/users/zardus","html_url":"https://github.com/zardus","followers_url":"https://api.github.com/users/zardus/followers","following_url":"https://api.github.com/users/zardus/following{/other_user}","gists_url":"https://api.github.com/users/zardus/gists{/gist_id}","starred_url":"https://api.github.com/users/zardus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zardus/subscriptions","organizations_url":"https://api.github.com/users/zardus/orgs","repos_url":"https://api.github.com/users/zardus/repos","events_url":"https://api.github.com/users/zardus/events{/privacy}","received_events_url":"https://api.github.com/users/zardus/received_events","type":"User","site_admin":false},"created_at":"2016-05-05T21:58:55Z","updated_at":"2016-05-05T21:58:55Z","body":"Oh dear...\r\n\r\nSo claripy uses ANA (https://github.com/zardus/ana) to store ASTs. ANA is a bit of a homespun serialization mess that does some tricks to avoid serializing the same AST multiple times. As these analyses tend to contain the same AST across many states, pickling ASTs multiple times takes up a disastrous amount of space. Instead, when an ANA object is pickled, the actual pickled data is stored in an ANA backend, and only the identifier is returned to Python.\r\n\r\nBy default, this backend is a dict in memory (`self._state_store`), which doesn't persist between different processes, as you're seeing. ANA also supports a filesystem backend and a mongodb backend (https://github.com/zardus/ana#storage-backends). You probably want the filesystem backend, which will store object states in pickles in a directory. You'll need to give it a directory to use, but that can be in `/dev/shm` if you want to use shared memory. ANA will store its data there, and the different processes will retrieve it.\r\n\r\nNote that this has no garbage collection with this at the moment. That's something that we still need to think about..."}}