{"action":"opened","number":22,"pull_request":{"url":"https://api.github.com/repos/tjfontaine/linode-python/pulls/22","id":29238134,"html_url":"https://github.com/tjfontaine/linode-python/pull/22","diff_url":"https://github.com/tjfontaine/linode-python/pull/22.diff","patch_url":"https://github.com/tjfontaine/linode-python/pull/22.patch","issue_url":"https://api.github.com/repos/tjfontaine/linode-python/issues/22","number":22,"state":"open","locked":false,"title":"Safe Pickling!","user":{"login":"tylerturk","id":6004145,"avatar_url":"https://avatars.githubusercontent.com/u/6004145?v=3","gravatar_id":"","url":"https://api.github.com/users/tylerturk","html_url":"https://github.com/tylerturk","followers_url":"https://api.github.com/users/tylerturk/followers","following_url":"https://api.github.com/users/tylerturk/following{/other_user}","gists_url":"https://api.github.com/users/tylerturk/gists{/gist_id}","starred_url":"https://api.github.com/users/tylerturk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tylerturk/subscriptions","organizations_url":"https://api.github.com/users/tylerturk/orgs","repos_url":"https://api.github.com/users/tylerturk/repos","events_url":"https://api.github.com/users/tylerturk/events{/privacy}","received_events_url":"https://api.github.com/users/tylerturk/received_events","type":"User","site_admin":false},"body":"### Reviewers\r\n- [ ] @tjfontaine  \r\n\r\n### Summary\r\nWhen leveraging the ```multiprocessing``` module, exceptions that are raised must be picklable. In order to be picklable, it seems that a class constructor must not have any undefined variables. There is a fairly detailed example on StackOverflow at the link below. I have also provided a sample that shows the before and after effect of these modifications. It looks like my ```.vimrc``` also sniped some whitespace from this script. Sorry about that!\r\n\r\nhttp://stackoverflow.com/questions/8785899/hang-in-python-script-using-sqlalchemy-and-multiprocessing\r\n\r\n### Approach\r\nWe instantiate the two ```value``` variables to be mutable strings.\r\n\r\n### Risk\r\nSignificantly low! :+1: \r\n\r\n### Sample script\r\n\r\n```\r\n#!/usr/bin/env python\r\n\r\nfrom random import randint\r\nfrom linode.api import ApiError\r\nfrom multiprocessing import Pool\r\n\r\n\r\ndef worker(d):\r\n    print \"Task initiated.\"\r\n    num = randint(1, 100)\r\n    if num < 30:\r\n        raise ApiError(\"Test\")\r\n    return num\r\n\r\n\r\ndata = [{}] * 20\r\npool = Pool(processes=20, maxtasksperchild=1)\r\nresult = pool.map(worker, data)\r\nprint result\r\n```\r\n\r\n### Smoke Test Instructions\r\n\r\nPrior to the modification, it is possible for processes to become stuck in a ```FUTEX_WAIT``` state:\r\n\r\n#### Script output prior to api wrapper modification\r\n```\r\n# python mp.py\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nException in thread Thread-3:\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python2.7/threading.py\", line 810, in __bootstrap_inner\r\n    self.run()\r\n  File \"/usr/lib/python2.7/threading.py\", line 763, in run\r\n    self.__target(*self.__args, **self.__kwargs)\r\n  File \"/usr/lib/python2.7/multiprocessing/pool.py\", line 380, in _handle_results\r\n    task = get()\r\nTypeError: ('__init__() takes exactly 2 arguments (1 given)', <class 'linode.api.ApiError'>, ())\r\n\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\n```\r\n#### Stuck system calls\r\n```\r\nroot     31088  0.5  0.1 275272 13156 pts/0    Sl+  03:27   0:00  |       \\_ python mp.py\r\nroot     31114  0.0  0.1 275272 10320 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31115  0.0  0.1 275272 10312 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31116  0.0  0.1 275272 10316 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31117  0.0  0.1 275272 10316 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31118  0.0  0.1 275272 10320 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31119  0.0  0.1 275272 10320 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31120  0.0  0.1 275272 10320 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31121  0.0  0.1 275272 10316 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31122  0.0  0.1 275272 10308 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31123  0.0  0.1 275272 10320 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31124  0.0  0.1 275272 10324 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31125  0.0  0.1 275272 10328 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31126  0.0  0.1 275272 10324 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31127  0.0  0.1 275272 10328 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31128  0.0  0.1 275272 10336 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31129  0.0  0.1 275272 10332 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31130  0.0  0.1 275272 10328 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31131  0.0  0.1 275272 10332 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31132  0.0  0.1 275272 10328 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\nroot     31133  0.0  0.1 275272 10328 pts/0    S+   03:27   0:00  |           \\_ python mp.py\r\n\r\nroot@hubby-v2-1:~# strace -p 31088\r\nProcess 31088 attached\r\nfutex(0x1b8d3f0, FUTEX_WAIT_PRIVATE, 0, NULL^CProcess 31088 detached\r\n <detached ...>\r\nroot@hubby-v2-1:~# strace -p 31114\r\nProcess 31114 attached\r\nread(3, ^CProcess 31114 detached\r\n <detached ...>\r\nroot@hubby-v2-1:~# strace -p 31115\r\nProcess 31115 attached\r\nfutex(0x7fcd6e7b6000, FUTEX_WAIT, 0, NULL^CProcess 31115 detached\r\n <detached ...>\r\nroot@hubby-v2-1:~# strace -p 31116\r\nProcess 31116 attached\r\nfutex(0x7fcd6e7b6000, FUTEX_WAIT, 0, NULL^CProcess 31116 detached\r\n <detached ...>\r\nroot@hubby-v2-1:~#\r\n```\r\n\r\n#### Script output after modification\r\n```\r\nroot@hubby-v2-1:~# python mp.py\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTask initiated.\r\nTraceback (most recent call last):\r\n  File \"mp.py\", line 18, in <module>\r\n    result = pool.map(worker, data)\r\n  File \"/usr/lib/python2.7/multiprocessing/pool.py\", line 251, in map\r\n    return self.map_async(func, iterable, chunksize).get()\r\n  File \"/usr/lib/python2.7/multiprocessing/pool.py\", line 558, in get\r\n    raise self._value\r\nlinode.api.ApiError: 'Test'\r\nroot@hubby-v2-1:~#\r\n```","created_at":"2015-02-13T03:33:12Z","updated_at":"2015-02-13T03:33:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tjfontaine/linode-python/pulls/22/commits","review_comments_url":"https://api.github.com/repos/tjfontaine/linode-python/pulls/22/comments","review_comment_url":"https://api.github.com/repos/tjfontaine/linode-python/pulls/comments/{number}","comments_url":"https://api.github.com/repos/tjfontaine/linode-python/issues/22/comments","statuses_url":"https://api.github.com/repos/tjfontaine/linode-python/statuses/3ab348742ef481692a1122dd905e48260218094d","head":{"label":"tylerturk:safe_pickle","ref":"safe_pickle","sha":"3ab348742ef481692a1122dd905e48260218094d","user":{"login":"tylerturk","id":6004145,"avatar_url":"https://avatars.githubusercontent.com/u/6004145?v=3","gravatar_id":"","url":"https://api.github.com/users/tylerturk","html_url":"https://github.com/tylerturk","followers_url":"https://api.github.com/users/tylerturk/followers","following_url":"https://api.github.com/users/tylerturk/following{/other_user}","gists_url":"https://api.github.com/users/tylerturk/gists{/gist_id}","starred_url":"https://api.github.com/users/tylerturk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tylerturk/subscriptions","organizations_url":"https://api.github.com/users/tylerturk/orgs","repos_url":"https://api.github.com/users/tylerturk/repos","events_url":"https://api.github.com/users/tylerturk/events{/privacy}","received_events_url":"https://api.github.com/users/tylerturk/received_events","type":"User","site_admin":false},"repo":{"id":25888453,"name":"linode-python","full_name":"tylerturk/linode-python","owner":{"login":"tylerturk","id":6004145,"avatar_url":"https://avatars.githubusercontent.com/u/6004145?v=3","gravatar_id":"","url":"https://api.github.com/users/tylerturk","html_url":"https://github.com/tylerturk","followers_url":"https://api.github.com/users/tylerturk/followers","following_url":"https://api.github.com/users/tylerturk/following{/other_user}","gists_url":"https://api.github.com/users/tylerturk/gists{/gist_id}","starred_url":"https://api.github.com/users/tylerturk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tylerturk/subscriptions","organizations_url":"https://api.github.com/users/tylerturk/orgs","repos_url":"https://api.github.com/users/tylerturk/repos","events_url":"https://api.github.com/users/tylerturk/events{/privacy}","received_events_url":"https://api.github.com/users/tylerturk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tylerturk/linode-python","description":"Linode API Python Bindings","fork":true,"url":"https://api.github.com/repos/tylerturk/linode-python","forks_url":"https://api.github.com/repos/tylerturk/linode-python/forks","keys_url":"https://api.github.com/repos/tylerturk/linode-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tylerturk/linode-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tylerturk/linode-python/teams","hooks_url":"https://api.github.com/repos/tylerturk/linode-python/hooks","issue_events_url":"https://api.github.com/repos/tylerturk/linode-python/issues/events{/number}","events_url":"https://api.github.com/repos/tylerturk/linode-python/events","assignees_url":"https://api.github.com/repos/tylerturk/linode-python/assignees{/user}","branches_url":"https://api.github.com/repos/tylerturk/linode-python/branches{/branch}","tags_url":"https://api.github.com/repos/tylerturk/linode-python/tags","blobs_url":"https://api.github.com/repos/tylerturk/linode-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tylerturk/linode-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tylerturk/linode-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/tylerturk/linode-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tylerturk/linode-python/statuses/{sha}","languages_url":"https://api.github.com/repos/tylerturk/linode-python/languages","stargazers_url":"https://api.github.com/repos/tylerturk/linode-python/stargazers","contributors_url":"https://api.github.com/repos/tylerturk/linode-python/contributors","subscribers_url":"https://api.github.com/repos/tylerturk/linode-python/subscribers","subscription_url":"https://api.github.com/repos/tylerturk/linode-python/subscription","commits_url":"https://api.github.com/repos/tylerturk/linode-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/tylerturk/linode-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/tylerturk/linode-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/tylerturk/linode-python/issues/comments/{number}","contents_url":"https://api.github.com/repos/tylerturk/linode-python/contents/{+path}","compare_url":"https://api.github.com/repos/tylerturk/linode-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tylerturk/linode-python/merges","archive_url":"https://api.github.com/repos/tylerturk/linode-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tylerturk/linode-python/downloads","issues_url":"https://api.github.com/repos/tylerturk/linode-python/issues{/number}","pulls_url":"https://api.github.com/repos/tylerturk/linode-python/pulls{/number}","milestones_url":"https://api.github.com/repos/tylerturk/linode-python/milestones{/number}","notifications_url":"https://api.github.com/repos/tylerturk/linode-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tylerturk/linode-python/labels{/name}","releases_url":"https://api.github.com/repos/tylerturk/linode-python/releases{/id}","created_at":"2014-10-28T20:22:54Z","updated_at":"2014-09-10T20:46:05Z","pushed_at":"2015-02-13T03:20:41Z","git_url":"git://github.com/tylerturk/linode-python.git","ssh_url":"git@github.com:tylerturk/linode-python.git","clone_url":"https://github.com/tylerturk/linode-python.git","svn_url":"https://github.com/tylerturk/linode-python","homepage":"http://www.linode.com/api","size":264,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tjfontaine:master","ref":"master","sha":"9ee60e8ba0557b68613cf52d8e4a6f926bdc797f","user":{"login":"tjfontaine","id":146447,"avatar_url":"https://avatars.githubusercontent.com/u/146447?v=3","gravatar_id":"","url":"https://api.github.com/users/tjfontaine","html_url":"https://github.com/tjfontaine","followers_url":"https://api.github.com/users/tjfontaine/followers","following_url":"https://api.github.com/users/tjfontaine/following{/other_user}","gists_url":"https://api.github.com/users/tjfontaine/gists{/gist_id}","starred_url":"https://api.github.com/users/tjfontaine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjfontaine/subscriptions","organizations_url":"https://api.github.com/users/tjfontaine/orgs","repos_url":"https://api.github.com/users/tjfontaine/repos","events_url":"https://api.github.com/users/tjfontaine/events{/privacy}","received_events_url":"https://api.github.com/users/tjfontaine/received_events","type":"User","site_admin":false},"repo":{"id":819566,"name":"linode-python","full_name":"tjfontaine/linode-python","owner":{"login":"tjfontaine","id":146447,"avatar_url":"https://avatars.githubusercontent.com/u/146447?v=3","gravatar_id":"","url":"https://api.github.com/users/tjfontaine","html_url":"https://github.com/tjfontaine","followers_url":"https://api.github.com/users/tjfontaine/followers","following_url":"https://api.github.com/users/tjfontaine/following{/other_user}","gists_url":"https://api.github.com/users/tjfontaine/gists{/gist_id}","starred_url":"https://api.github.com/users/tjfontaine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjfontaine/subscriptions","organizations_url":"https://api.github.com/users/tjfontaine/orgs","repos_url":"https://api.github.com/users/tjfontaine/repos","events_url":"https://api.github.com/users/tjfontaine/events{/privacy}","received_events_url":"https://api.github.com/users/tjfontaine/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tjfontaine/linode-python","description":"Linode API Python Bindings","fork":false,"url":"https://api.github.com/repos/tjfontaine/linode-python","forks_url":"https://api.github.com/repos/tjfontaine/linode-python/forks","keys_url":"https://api.github.com/repos/tjfontaine/linode-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tjfontaine/linode-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tjfontaine/linode-python/teams","hooks_url":"https://api.github.com/repos/tjfontaine/linode-python/hooks","issue_events_url":"https://api.github.com/repos/tjfontaine/linode-python/issues/events{/number}","events_url":"https://api.github.com/repos/tjfontaine/linode-python/events","assignees_url":"https://api.github.com/repos/tjfontaine/linode-python/assignees{/user}","branches_url":"https://api.github.com/repos/tjfontaine/linode-python/branches{/branch}","tags_url":"https://api.github.com/repos/tjfontaine/linode-python/tags","blobs_url":"https://api.github.com/repos/tjfontaine/linode-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tjfontaine/linode-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tjfontaine/linode-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/tjfontaine/linode-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tjfontaine/linode-python/statuses/{sha}","languages_url":"https://api.github.com/repos/tjfontaine/linode-python/languages","stargazers_url":"https://api.github.com/repos/tjfontaine/linode-python/stargazers","contributors_url":"https://api.github.com/repos/tjfontaine/linode-python/contributors","subscribers_url":"https://api.github.com/repos/tjfontaine/linode-python/subscribers","subscription_url":"https://api.github.com/repos/tjfontaine/linode-python/subscription","commits_url":"https://api.github.com/repos/tjfontaine/linode-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/tjfontaine/linode-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/tjfontaine/linode-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/tjfontaine/linode-python/issues/comments/{number}","contents_url":"https://api.github.com/repos/tjfontaine/linode-python/contents/{+path}","compare_url":"https://api.github.com/repos/tjfontaine/linode-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tjfontaine/linode-python/merges","archive_url":"https://api.github.com/repos/tjfontaine/linode-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tjfontaine/linode-python/downloads","issues_url":"https://api.github.com/repos/tjfontaine/linode-python/issues{/number}","pulls_url":"https://api.github.com/repos/tjfontaine/linode-python/pulls{/number}","milestones_url":"https://api.github.com/repos/tjfontaine/linode-python/milestones{/number}","notifications_url":"https://api.github.com/repos/tjfontaine/linode-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tjfontaine/linode-python/labels{/name}","releases_url":"https://api.github.com/repos/tjfontaine/linode-python/releases{/id}","created_at":"2010-08-05T16:38:26Z","updated_at":"2015-01-13T02:26:09Z","pushed_at":"2014-12-08T01:10:43Z","git_url":"git://github.com/tjfontaine/linode-python.git","ssh_url":"git@github.com:tjfontaine/linode-python.git","clone_url":"https://github.com/tjfontaine/linode-python.git","svn_url":"https://github.com/tjfontaine/linode-python","homepage":"http://www.linode.com/api","size":535,"stargazers_count":110,"watchers_count":110,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":33,"mirror_url":null,"open_issues_count":3,"forks":33,"open_issues":3,"watchers":110,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tjfontaine/linode-python/pulls/22"},"html":{"href":"https://github.com/tjfontaine/linode-python/pull/22"},"issue":{"href":"https://api.github.com/repos/tjfontaine/linode-python/issues/22"},"comments":{"href":"https://api.github.com/repos/tjfontaine/linode-python/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/tjfontaine/linode-python/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/tjfontaine/linode-python/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/tjfontaine/linode-python/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/tjfontaine/linode-python/statuses/3ab348742ef481692a1122dd905e48260218094d"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":9,"deletions":9,"changed_files":1}}